How to get my external IP address (over NAT) from the Windows command-line? [duplicate]
Solution 1:
Now, using the site Oliver provided, this can be done in VBScript.
Dim o
Set o = CreateObject("MSXML2.XMLHTTP")
o.open "GET", "http://ifconfig.me/ip", False
o.send
WScript.StdOut.Write o.responseText
There's a similar method for PowerShell.
Solution 2:
The problem is, it's not your IP address. It's the IP address of your router.
So you will never be able to retrieve it without going through your router. And the easiest way is to simply make the router retrieve a website for you (as you've already noticed). Because the router will use its IP address to retrieve that site.
That being said, you can make it easy on yourself by using ifconfig.me/ip. Now, if you have curl
, you're already done, if not: Wget/cURL alternative native to Windows?
Solution 3:
Create a VB script to run at your leisure.
Type this into a txt file:
Option Explicit
Dim http : Set http = CreateObject( "MSXML2.ServerXmlHttp" )
http.Open "GET", "http://icanhazip.com", False
http.Send
Wscript.Echo http.responseText 'or do whatever you want with it
Set http = Nothing
Close the txt file and rename it to ip.vbs (save it to C: for this example)
In windows open a dos window (run cmd) (ha! I just realised if you swap that it becomes run dmc!!)
Make sure you're in c:/ (if not, type c: & press enter, then cd.. & enter a few times until you see C:>)
At the dos prompt type:
cscript ip.vbs
and you will instantly see your external IP.
If you put the vbs file onto a usb key or something (and remember to run cscript ip.vbs at the dos prompt - but make sure you're in the same directory as the ip.vbs file), you can take this with you anywhere you go and run the .vbs file on any computer to see their external IP.
One other note, the line that has the address for icanhazip.com can be changed to any of the following:
http://myip.dnsomatic.com
http://whatismyip.org
http://icanhazip.com
http://www.whatismyip.com/automation/n09230945.asp
http://externip.com
Edit, you can also run the ip.vbs file in windows without going to a dos window and it will just show up in a little pop up window.