16

The Windows "ipconfig" command can only show me the parameters from the Ethernet interfaces from my machine (even with the ipconfig /all argument). It can show detailed information about the interface, but it will never show me my external IP address over a NAT network.

ipconfig/all -- Windows screenshot

However, there are several websites, such as "What is my IP address" that can get and show my external IP address. So I'm wondering, whether it is possible to get this value externally? Should I expect that there is some way to get this information from a command line at my local machine...

I need to get this value to log on an application that I'm doing with VBScript. Is there a way to do this, from a cmd on Windows?

Diogo
  • 30,792

8 Answers8

12

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.

Bob
  • 63,170
10

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?

Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311
6

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.

Champ
  • 61
  • 1
  • 2
5

I stumbled on this site when looking for the PowerShell equivalent and I thought I would share this command should anyone else be looking:

Invoke-WebRequest ifconfig.me/ip

More details are available here should you need them - http://jfrmilner.wordpress.com/2012/12/22/powershell-quick-tip-03-whats-my-external-ip-address-windows-command-line/

Irfan
  • 241
jfrmilner
  • 2,197
3

To get a external IP address, you need to ask something outside of the network and have it report back what your IP address "appears" to be to it. This can be done through scripting by querying a page that is easy to parse the result from and getting the IP address from that, but there is no tool built into Windows that you can just tell you what your external IP address is. You will need to write one yourself or find one and download it.

2

Using something like DynDNS to assign your DHCP IP address a domain name, you could then do an nslookup of, or ping (if your router's configured to respond), your domain name and extract the IP address from that.

The only other Windows utility is traceroute, but it would only show the outbound gateway you connect to, not your router's IP address that's connecting to that gateway.

Edit: As it takes a bit of parsing on the above to extract the IP address string and ifconfig.me has a nice sparse response, here's a little bit of a variant on Bob's script, the function can test for no response and give back a nice clean IP address for use in a script if the server is up.

wscript.echo WAN_IP()

function WAN_IP()
    set obj = createobject("Microsoft.XMLHTTP")
    call obj.open("get", "http://ifconfig.me/ip", false)
    obj.send()

    strresponse = obj.responsetext
    set obj = nothing

    if strresponse <> "" then
        strIP = strresponse
    else
        strIP = "Unavailable"
    end if

    WAN_IP = trim(strIP)

end function
Fiasco Labs
  • 6,864
1

If your router support Universal plug & Play (UPnP) you can query it's IP address(es).

On Windows you can query such information using WMI and from command-line using the WMIC tool.

Robert
  • 8,055
1

As others have already said, you need to rely on an external service. I'd recommend http://www.externalip.net

You can use http://api.externalip.net/ip to get the ip in plain text format. It has proven to be fast and reliable, plus it has unlimited use.