Welcome!

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

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

Code:
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

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

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.

[/code]
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
108.12.0.196[/code]

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

1680125785861.png
 
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:

Code:
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:
Code:
(Invoke-WebRequest ifconfig.me/ip).Content.Trim()

Within TCC, you could do the following:
Code:
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.

Code:
type https://ifconfig.me/ip

This one also works:

Code:
type http://myip.dnsomatic.com
 

Similar threads

Back
Top