What Is My IP?

UPDATE 5/27/15: WhatsMyIP.Me now gets 5,000 hits an hour! Incredible!

I recently have been experiencing issues at work where one of my two ISP’s would go down. I have a Cisco firewall that handles the fail over to my backup connection, so most of my users were unaffected.

The only users who even noticed were those who frequented websites who had additional security featues enabled to prevent against session hijacking. The constant ISP failover behaved like a multi-homed network that would randomly serve web pages across more than one Internet provider on a page by page basis.

This was a bit tricky to debug, so my first step was to create a php script that would let me know what is my external ip address, whatsmyip.me . I felt the need to create my own as many of the existing services that tell you your IP address are covered in advertisements and I just wanted a tool that would return the external IP address and nothing more. Also, most of them do a terrible job at detecting proxies and return incorrect information.

whatsmyip.me is a single php script and the code is below:

<?PHP
function whatsMyIP()
{ 
  foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key)
  {
      if (array_key_exists($key, $_SERVER) === true)
      {
        foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip)
          {
              if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false)
              {
                  return $ip;
              }
          }
      }
    }
}
 
$users_ip = whatsMyIP();
echo $users_ip; // Output IP address [Ex: 123.12.41.42]
?>

I also put this on github under “What Is My IP”

The way this script works by analyzing the php $_SERVER variable ( an array containing information such as headers, paths, and script locations created by the webserver) and returning the most reliable IP address possible. Please note, the only address you can really trust is REMOTE_ADDR, because it is the source IP of the TCP connection and cant be changed by spoofing/changing an http header. While it is technically possible to bidirectionally spoof IP addresses at the Border Gateway level, but you would have to have control over an ISP to do so.

After I had the webservice to accurately give me my ip address, i created a single bash file that would echo my IP address every 15 seconds for the next 24 hours.

MPB:dconroy$ for i in `seq 1 5760`;do  date;curl http://whatsmyip.me;sleep 15; done

If your linux box is in a different timezone, you can use the TZ environment variable to report back the correct time. In my case i just added ‘TZ=America/New_York’ directly before ‘date’.

Using this, I was able to pinpoint the exact windows where my ISP would drop making my technical support calls much more productive. This is what I love about linux and raspberry pi’s – if the tool you are looking for doesnt exist, build one!

Read More

War ‘Shipping’

War driving – the act of searching for Wi-Fi wireless networks by a person in a moving vehicle, using a portable computer, smartphone or personal digital assistant (PDA).

My initial idea for War ‘Shipping’ was in April 2011. The plan was to write some custom code for a low-end android phone that would force it to automatically join open Wi-Fi networks. If the phone was able to get on the internet, it would then report its GPS location back to me.

At that point, I would hook up the phone up to an external battery and ship it UPS ground across the country. My theory is that my phone would be able to join at least 50 networks by the time it got to California or the battery died.

I’ve got the code complete and my test runs have been very successful.
drive-to-work

I’m looking for volunteers in California to help me test it. Interested? Let me know.

Read More

Hubway’s Data Visualization Challenge

This is my entry to Hubway Data Visualization Contest. I thought it’d be interesting to see the fastest bikers inbetween every station, and at what times of day the rides occurred. I’ve also created a few awards for special categories. For Example, I’ve given awards to the “Fastest Sprinter”, the rider who traveled fastest under 2000 meters.

To see the winners of the custom awards, click here.

hubway data visualization contest
To see the fastest trips between specific stations, click here.

For other ideas and a work log, please check my about page.

hubway data visualization contest

 

 

Read More