Command/Batch File to Get Public IP Addresses

Jun 2, 2008
Newton, MA
Does anyone have a command or batch file that gets one's external IP addresses?

There are lots of websites that will display the information, but extracting the data does not look like an easy task. Perhaps someone else has already worked this out.

-- Jay
This should require no new software.

echo IP address is now %@word[1,%@execstr[4,nslookup -type=a 2>nul]]

Here's another if you have DIG.EXE

echo %@execstr[d:\dig\dig.exe +short]
Opendns does not work for me within our corporate environment.
nslookup -type=a
DNS request timed out.
    timeout was 2 seconds.
Server:  UnKnown

DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
*** Request to UnKnown timed-out
Another (thanks Scott). This is a first attempt; maybe it could be made more elegant.

v:\> type What Is My IP Address? (IPv4 & IPv6) - Show My IP | findstr ipv4 | head /n1 | tpipe /replace=4,0,0,0,0,0,0,0,0,"^.*>(.*)<.*$",$1[/code]

Hmmm! The forum is doing funny things. That should look like this.

Thanks everyone. I took Scott's original suggestion and turned it into an elaborate batch file that gets the current public IP4 address, optionally logs it to a file with a date stamp, and tells me if it has changed since the value was last logged. This is now called as part of my TCSTART.BTM.
Now you tell me -- after I wrote all the code to extract the value using Scott's command :-)

Thanks. Your URL certainly makes things a lot easier, and I updated my batch file. (But it is better to use https.) I kept the old code, but commented out, just in case "" goes away.
Or with Powershell, try:

Within TCC, you could do the following:
pshell /s "(Invoke-WebRequest"

Similar threads