By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Command/Batch File to Get Public IP Addresses

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
Try this:
echo "%@execstr[curl -s https://showmyip.com|find "ipv4"]"
This should require no new software.

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

Here's another if you have DIG.EXE

echo %@execstr[d:\dig\dig.exe +short myip.opendns.com @resolver1.opendns.com]
Opendns does not work for me within our corporate environment.
nslookup -type=a myip.opendns.com resolver1.opendns.com
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.
Just to pile on, I use the following:

type http://dynamicdns.park-your-domain.com/getip
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 "dynamicdns.park-your-domain.com/getip" goes away.
Or with Powershell, try:
(Invoke-WebRequest ifconfig.me/ip).Content.Trim()

Within TCC, you could do the following:
pshell /s "(Invoke-WebRequest ifconfig.me/ip).Content.Trim()"
That's a good one Alpengreis. You can also just 'type' it and get a direct IP. I'll setup this as my backup.

type https://ifconfig.me/ip

This one also works:

type http://myip.dnsomatic.com
[FOX] Ultimate Translator