Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
on windows that is – Junaid Saeed Jul 21 '10 at 6:06

7 Answers

up vote 6 down vote accepted

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.)

share|improve this answer
They changed whatismyip.org, unfortunately; the IP address is now returned as an image, making it pretty much useless for scripting. The website "icanhazip.com" mentioned below does work. – onnodb Nov 29 '12 at 13:53

grab your own copy of curlfrom 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)

share|improve this answer

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:

(source: formerly http://externip.com/about)

share|improve this answer

I made this batch script to do that a few months ago:

@echo off

:: WhatIsMyIP.cmd - returns public IP address
:: requires: wget.exe

if [%1]==[-h] goto :HELP
if [%1]==[--help] goto :HELP
if [%1]==[/?] goto :HELP

wget -q -O %temp%\MyIP http://www.whatismyip.com/automation/n09230945.asp
for /f "delims= " %%G in (%temp%\myip) do set PublicIP=%%G & del %temp%\MyIP
echo. & echo Your public IP address is %PublicIP% & echo.
if [%1]==[--clip] echo %PublicIP% | clip
goto :EOF

:HELP
echo. & echo Usage: whatismyip [--clip] & echo.
goto :EOF

:EOF

It gives you the option to put the IP address in the clipboard and it sets an environmental variable - %PublicIP%.


SIMPLER METHOD:

Now, I just do this instead:

curl icanhazip.com

or...

curl icanhazip.com | clip

...to get the current public IP address into the clipboard.

You need cURL.

share|improve this answer

The script from paradroid worked fine but whatsmyip moved the web page to http://automation.whatismyip.com/n09230945.asp

If you change to this, it works perfect.

share|improve this answer

Are you able to log into your router? Should find the info there, like on a Status page.

Using a Mozilla browser & NoScript? NoScript Options | Advanced | ABE -> WAN IP.

share|improve this answer

You can deduce the IP on a simple network by running TRACERT. At a command prompt type tracert www.google.com or another well know web site. You will likely see the first hop is your inside interface(default Gateway) of your router. You should then see the next hop which is the external interface and the IP you are looking for. Works for most simple networks with one router and internal network.

share|improve this answer
I'm not sure that's right. Normally you would see your internal IP, then your ISP's/company's server in your town. This is because the TTL exceeded happens on incoming packets, not outgoing packets. – Mikel Feb 12 '11 at 3:28
Tested on two different networks and it shows default gateway and then teh exteranl IP. Perhaps other networks are different. – Dave M Feb 14 '11 at 13:21
The 2nd hop is NOT the external ip assigned to your router. I thought this too for a moment. It's actually your ISP's router. – Matt H Apr 4 at 23:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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