Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
Note that HTTP based what-is-my-IP services may give you the IP of a proxy server. (And before anyone points out that HTTPS proxies exist, you can't transparently proxy HTTPS. If you've got one, you'll know it.) –  billpg Mar 26 '12 at 20:04

8 Answers 8

up vote 8 down vote accepted

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.

share|improve this answer
    
Nice, it worked. I will insert it on my program. Its a good solution for my problem. Thank you. –  Diogo Mar 26 '12 at 15:10
    
Hmm, it is returning a "Acess denied" on line 4, character 1 for this script. Even running it from a administrator rights command line... Do you know why? –  Diogo Mar 26 '12 at 17:58
    
@DiogoRocha I don't know why. Fiasco's one is probably more reliable. It's also possible you have a firewall or something blocking internet access to wscript/cscript. –  Bob Mar 27 '12 at 5:32

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?

share|improve this answer
1  
ifconfig.me/ip took a long time to load. whatismyip.org gives you an identical plain-text IP and was a lot faster. –  nhinkle Mar 27 '12 at 3:29
1  
@nhinkle That might depend on your location, though. They both appear to have the same load time for me, but ping response time from ifconfig.me is half (139ms vs 250ms). What's probably more important is that the service stays up for as long as possible, but we really have no way of knowing. –  Bob Mar 27 '12 at 5:27
    
There's nothing wrong with the external IP addres of my router considering port forwarding rules and IPv4. –  mbx May 7 at 17:09

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.

share|improve this answer

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.

share|improve this answer

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
share|improve this answer

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/

share|improve this answer

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.

share|improve this answer
1  
Could you provide an example? I'd be very interested in this. –  Oliver Salzburg Mar 26 '12 at 15:21

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.

share|improve this answer

protected by Diogo Sep 12 '13 at 17:22

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.