How to Tweet Your Machine’s IP

Tweeting My Machine’s IP

So I wanted to connect to my ubuntu server, unfortunately I don’t have a static ip and I’m not planning to get one, so i had to find a work around.

My first thought was to develop an app that reads my IP from http://www.whatsmyip.net and then publishing it somehow whenever it changes, but later on i decided to tweet it instead because given my connection state my inbox would be buried in one lined emails, not to mention its too much of a hassle to actually log in and read it, as a result I decided to tweet it instead, also i decided to use Java instead of shell scripting because i have another windows machine that i want to deploy this on it as well.

First of all i located an easy to use twitter java library which turned out to be twitter4j, starting from there it wasn’t that challenging. It reads whatsmyip.net html page, parsing the <title> tag which includes the ip address, then checks ip against the last posted ip if they are equal nothing happens if they are different a new ip is posted, this happens every 4 minutes (which is think is too frequent but well you can change it if you want to).

I included the source code, as well as the twitter4j library…ENJOY

Click here to download file

How to :

  1. modify file tweeterer to include your twitter user name and password (dont forget to keep that twitter account private using twitter security features
  2. Recompile using javac
  3. use java -jar IPTweeter.jar
  4. to make sure that this runs whenever the machine starts by placing a simple script in your /etc/init.d/ folder.
  5. or you can just add it to the crontab
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s