Jackson I/O
What's My IP Address?

If you search any search engine for "What's my IP address?" or "Find my IP address" or similar, you'll get lots of links to web pages that show you your external IP address.  And this link is yet another, but with a difference: http://queryip.net/ip/

Note: The old link, http://jackson.io/ip/, still works, but sadly, DNS service for this domain has proven to be unreliable.  Therefore I recommend you use the new one.  It's the same service (even the same server IP address), but I expect it to be more stable.

A Service to Find Your IP Address

This page describes a service for finding your IP address and how and why to use it.

(find IP icon)

What makes http://queryip.net/ip/ different is the brevity of the response.  It contains only the IP address of the computer that fetched it with no advertisements, no explanation, no HTML or formatting, and not even a carriage return or line feed character.  You can fetch it with a web browser, but it is most useful if you want to write a script which automatically fetches it with a scriptable tool like curl, wget, or BSD's fetch.  (Windows is discussed later.)

Here are examples of how to use these tools to put your IP address in an environment variable in a shell script:

IP="$(curl -s http://queryip.net/ip/)"
IP="$(wget -o/dev/null -O- http://queryip.net/ip/)"
IP="$(fetch -qo- http://queryip.net/ip/)"

If you do that with the other sites, you will have to write additional code to scrape away the HTML, text and advertisements.  If the format or even the advertisements change, your script may break.

Why this is Useful

This is particularly useful if your PC has a local network IP address that is translated to a shared external IP address by a cable modem, DSL modem, or router.  In such a case, it may not be easy to query the modem or router to get the external IP address.

But why do you need to know the external IP address?  You need to know it to setup a VPN, SSH connection, or various other networking or client-server or peer-to-peer programs.  Also, on one occasion I had to email my IP address before being authorized to login to some site.

Remote Detection

It's one thing to find out the IP address while you are actually at that site, but it would also be helpful to find it while you are at a remote site.  That is, you may be at work trying to setup your VPN to home and you need to know your home IP address.  One way to get it is to wait until you get home and use the URL above.  But that may be inconvenient.

Worse, most homes and many offices have dynamic IP addresses.  Anytime there is a power- or service-interruption or when the DHCP "lease" expires, a new and different IP address can be automatically assigned.  If the affected users are only browsing and using email, this is a transparent operation that would not even be noticed.  But a VPN or SSH connection will stop working when one of the IP addresses changes.

To avoid physically going to the other site every time the dynamic IP changes, some people use Dynamic DNS as described below.  The implementation presented here is a third way.  (1: Go there, 2: Use DDNS, or 3: Do this)

Implementation

The mechanism is for each site (household) to write it's own IP address to a tiny text file on some publicly accessible website.  Most ISPs now provide a small amount of web space included with each account, which is a perfect place to store the tiny text file.

If you are using a Windows PC and have not installed any version of the bash shell, skip on down to "Implementation on Windows."  All others run a script like the following on your home PC once a day or so, typically as a cron job.  It writes the IP address to the tiny text file.  Of course, you must substitute your ISP's site and your username and password.

#!/bin/sh
SITE=upload.comcast.net
FILE=ip_at_home.txt
USER=username
PW=password
IP="$(curl -s http://queryip.net/ip/)"
if [ "$IP" != "" ]; then
   echo $IP | curl -s --upload-file - "ftp://$USER:$PW@$SITE/$FILE"
fi

Then at the remote PC, say at work, put this script in a directory on your path.  Name it homeip.  Unlike the script for writing the tiny text file, reading it does not require the password.

#!/bin/sh
curl -s http://home.comcast.net/~username/ip_at_home.txt

Now, any time you are at work and need to know the real (external) IP address of your home PC, simply run the homeip command and it will spit it out.  You can even call this from other scripts.

This exact process can be repeated, even using the same website, to write your work IP address, but to a different file, say ip_at_work.txt.

Implementation on Windows

Windows does not come with any helpful tool like curl, and the scripting languages are more challenging than on any other operating system.  Therefore, it is recommended to install something like the Cygwin environment which gives the capability to run shell scripts as cron jobs so the procedure above can be followed.  Alternately, a standalone Windows version of wget is available from the GnuWin32 project.

But even a naked Windows PC can implement this with the following VBScript script run by the Windows Scheduled Tasks service.  Note that no error checking is done and there is no confirmation output.

' Execute: cscript //nologo save_ip.vbs
'
' Change these:
ftp_server = "ftpmysite.verizon.net"
username = "username"
password = "password"
ip_filename = "home_ip.txt"

' Create objects
set ip = createobject("Microsoft.XMLHTTP")
set fs = createobject("Scripting.FileSystemObject")
set sh = createobject("WScript.shell")

' Fetch the IP address
ip.open "GET", "http://queryip.net/ip/", false
ip.send(null)

' Create the small text file to be written to the FTP server
ip_pathname = fs.GetSpecialFolder(2) & "\" & ip_filename
if (fs.FileExists(ip_pathname)) then
fs.DeleteFile(ip_pathname)
end if
set f = fs.CreateTextFile(ip_pathname)
f.Write(ip.responseText)
f.Close
set ip = nothing : set f = nothing

' Create a script for FTP
script_name = fs.GetSpecialFolder(2) & "\" & fs.GetTempName
set script = fs.OpenTextFile(script_name, 2, true)
script.writeline "open " & ftp_server
script.writeline username
script.writeline password
script.writeline "put " & ip_pathname & " " & ip_filename
script.writeline "close"
script.writeline "quit"
script.close

' Run FTP with the script and cleanup
sh.Run "ftp -s:" & script_name, , true
set sh = nothing : set script = nothing
fs.DeleteFile(script_name)
set fs = nothing

How the Mechanism Works

You don't even need to know how the service site gets your IP address to use it.  But for the curious, here is how it works.

The default file in the /ip/ directory is index.php, which contains only one line: "<?php echo $_SERVER['REMOTE_ADDR'] ?>", with no carriage returns or line feed characters.  Since it's a php file, PHP processes it and replaces the global variable with the destination IP address.

Note that the filename index.php would change if a different mechanism is employed, e.g. a CGI script.  Therefore, to be safe, use the URL as given with no file name, http://queryip.net/ip/.

Dynamic Domain Name System

To avoid physically going to the other site everytime the dynamic IP changes, some people choose to use one of the free dynamic DNS services.  The following sites provide both free domain names and free DDNS hosting:

These sites provide free domain names, but no DNS service:

These sites provide free DNS services, but not domain names:

Most of these sites offer tools to automatically update the chosen hostname's assigned IP address when it changes.  Once this is setup, the user uses regular old DNS to retrieve the IP address.

Note that even if you are using a DDNS service, you automatically update it in some way, so the service presented above may still be useful to learn your IP address.

Miscellaneous Domain Tools
Reverse IP
DNS Domain Check Tool from seologs.com.
My IP Neighbors
Similar to seologs.com
IP Address Lookup
Info about and map location of IP address.
SPF Validation
Test which domains can be sent from an SMTP server.
DNS Report
Test 56 DNS issues.  (Delete the cookie from dnsstuff.com to do more free tests.)
Mail Relay Testing
robotex DNS records
Other Interesting Sites
InfoSniper
Shows a map that locates an IP address geographically.
Site Navigation
External Links:
Open Source
Contact



Get Firefox! Get GNU/Linux Validate XHTML 1.0 Strict Validate CSS Speakeasy Speed Test Linux Forums Wikipedia Project Honey Pot Morningstar Corporation ohloh software stack

These dummy email addresses are for harvesters, but they should be invisible to browsers.
Several dummy email addresses that bounce back.











Creative Commons License This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License Attribute to the URL or http://jackson.io/. nevermind

Modified Oct 31, 2012