Windows command that returns external IP
Is there a command by which I can find my external IP of my router or my NAT\DSL Router, etc., eliminating the need to visit whatsmyip.net or similar.
Solution 1:
There is no built-in command to do this. Part of the problem is that when you are connected to the internet through a router, your network hardware is not directly connected to the internet, so your system isn't specifically assigned an IP. It's possible you might even have multiple external IPs in some cases if you are behind a reverse proxy, as many corporate networks are set up. Your best bet might be to create a script which queries whatismyip.org, or trying to find if one already exists.
(As a tip, whatismyip.org is preferable to most other solutions, since it just returns your IP as plain text - no superfluous text, links, images or other garbage. It would be much easier to use in a custom script than most of the other IP-detection sites.)
Solution 2:
You could use a DNS request instead of HTTP request to find out your public IP:
C:\> nslookup myip.opendns.com. resolver1.opendns.com
It uses resolver1.opendns.com
dns server to resolve the magical myip.opendns.com.
hostname to your ip address. (Note: the trailing .
on the lookup prevents search domains from being appended, which can yield incorrect results.)
Unix version:
$ dig +short myip.opendns.com @resolver1.opendns.com
Solution 3:
grab your own copy of curl
from http://curl.haxx.se/download.html and then just
curl "http://myexternalip.com/raw"
or use powershell:
$wc = new-object System.Net.WebClient
$wc.DownloadString("http://myexternalip.com/raw")
(disclaimer: http://myexternalip.com was created by me)
Solution 4:
This works nicely, I use it mostly with psexec when inspecting client computer connections.
nslookup myip.opendns.com resolver1.opendns.com
Solution 5:
Create a file named ip.vbs
and copy the following into it:
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
Execute using
C:\>cscript ip.vbs
As nhinkle noted, it's best to choose a site that only returns the IP and not HTML + ads, etc. like:
- http://myip.dnsomatic.com
- http://whatismyip.org
- http://icanhazip.com
- http://www.whatismyip.com/automation/n09230945.asp
(source: formerly http://externip.com/about)