Command line utility to get external IP address

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Command line utility to get external IP address

Post by John Gray »

I've been Googling this without any real success, and wonder whether someone knows of a command line utility which gives me my real external IP address. Maybe something like netsh or one of the more obscure networking utilities.

I say "real" because even websites like whatismyip.com give the target address of a VPN I may have set up; when I disconnect it, the answer reverts back to my correct IP address!
John Gray

Venison is quiet deer, and quite dear.

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Command line utility to get external IP address

Post by StuartR »

you may have multiple "real" IP addresses, but you will get them all with

Code: Select all

ipconfig | Find "IPv4"
I'm sure you can do the DOS magic to extract the IP address from the output line(s)
StuartR


User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Command line utility to get external IP address

Post by John Gray »

Thanks, Stuart - but did you miss the magic word "external"?!
John Gray

Venison is quiet deer, and quite dear.

User avatar
Argus
GoldLounger
Posts: 3081
Joined: 24 Jan 2010, 19:07

Re: Command line utility to get external IP address

Post by Argus »

Have you read this thread, at Raymondcc, about using wget:
http://www.raymond.cc/forum/software/10 ... al-ip.html" onclick="window.open(this.href);return false;
Perhaps you have, or it gives you the same result. Don't know about your VPN, however.
Byelingual    When you speak two languages but start losing vocabulary in both of them.

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Command line utility to get external IP address

Post by John Gray »

Thanks, Argus - I have just found that while at work! I (obviously!) haven't tried it at home, yet, where I use the VPN.

I'm hoping for a single utility which will give me the answer immediately, and correctly, but there doesn't seem to be one.
John Gray

Venison is quiet deer, and quite dear.

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Command line utility to get external IP address

Post by StuartR »

John Gray wrote:Thanks, Stuart - but did you miss the magic word "external"?!
John,

I didn't so much miss the word, as not know what it means.

In my case I have an IP address for the Ethernet connection, this is only really visible to my router, which uses NAT to present a completely different IP address to the outside world. In addition I have a separate IP address for my VPN connection (because I use "split tunnelling" both this IP addresses and the IP address of the router may be visible to other computers). ALSO some of my activities make use of a proxy server, which presents a completely different IP address to the external world.

Which one of these addresses would you call "real external IP address"?
StuartR


User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Command line utility to get external IP address

Post by ChrisGreaves »

John Gray wrote:... my real external IP address.
John! Don't tell me that you, too are into Astroturfing? :evilgrin:

b. Automatically provide its astroturfers with "randomly selected IP addresses through which they can access the internet" (an IP address is the number which identifies someone's computer), and these are to be changed every day, "hiding the existence of the operation". The software should also mix up the astroturfers' web traffic with "traffic from multitudes of users from outside the organisation. This traffic blending provides excellent cover and powerful deniability."
An expensive day out: Wallet and Grimace

User avatar
Argus
GoldLounger
Posts: 3081
Joined: 24 Jan 2010, 19:07

Re: Command line utility to get external IP address

Post by Argus »

John Gray wrote:I'm hoping for a single utility which will give me the answer immediately, and correctly, but there doesn't seem to be one.
There probably is, but it has to look at it from the outside; and then you'll have to use some web service or a custom made thingy.

Here's an interesting article, doing some more things, I know, but still interesting, where they have created an application that retrieves the IP address of a remote machine and then e-mails it to a mailbox; the author is giving support to a relative, and needs a simple way to get the address. As we all know, being behind a router means that we have to use and rely on some external service, or site, or perhaps ask the router, somehow. In this case it creates a new web service, custom web page that retrieves the header information, and then returns it to the client application, quite nifty.
http://msdn.microsoft.com/en-us/magazine/cc163692.aspx" onclick="window.open(this.href);return false;

Anyhow, you may have also seen that Daniel Petri has written about it as well. Here's one of the articles:
http://www.petri.co.il/showmyip.htm?wp7 ... e=&accent=" onclick="window.open(this.href);return false;

And as you know, there are several threads at Microsoft's forums about this, people developing different tools.
Byelingual    When you speak two languages but start losing vocabulary in both of them.

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Command line utility to get external IP address

Post by John Gray »

By "external IP address" I mean "that IP address which is assigned to my router (or cable modem) by my ISP" - you know, the one they change without notice after about three years of it staying the same, and screwing up a program which relies on an IP address as some sort of security check!

I want to run something at startup-time which will compare current external IP address with yesterday's, to warn me that I need to do some configuration changes for this program, rather than faff around for hours, eventually working out that that was the problem!
John Gray

Venison is quiet deer, and quite dear.

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Command line utility to get external IP address

Post by StuartR »

John,

I don't think there is an easy way to get what you are asking for, because of the possible effect of VPN or Proxy services between you and any server that you could interrogate.

I don't suppose your router has a telnet interface that accepts command line input. This would provide one way of doing it.
StuartR


User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Command line utility to get external IP address

Post by John Gray »

Petri's stuff is interesting, and I've added a couple more web-site IP address informers from his webpage, so I can see which still give the correct external IP address

However his link to CMDnet (which looked like just the utility I wanted) fails, and I had some trouble tracking down a copy.

Running CMDnet at work gives the external IP address as 127.0.0.1, which doesn't fill me with much confidence that it will work at home...
John Gray

Venison is quiet deer, and quite dear.

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Command line utility to get external IP address

Post by John Gray »

StuartR wrote:I don't think there is an easy way to get what you are asking for, because of the possible effect of VPN or Proxy services between you and any server that you could interrogate.
I see what you mean - a little - but an external website must have a consistent IP address to which to send data, regardless of whether or not a VPN has been connected! It's that address I'm trying to find by using a command-line utility (which of course will need some webby content...)
John Gray

Venison is quiet deer, and quite dear.

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Command line utility to get external IP address

Post by StuartR »

Depending on your router, you may be able to get what you want from the DOS tracert command. This doesn't work with my router as it fails to respond to the ICMP ECHO requests.
StuartR


User avatar
Argus
GoldLounger
Posts: 3081
Joined: 24 Jan 2010, 19:07

Re: Command line utility to get external IP address

Post by Argus »

If not including the VPN and proxies in the issue, though I do understand that that is a central part of the question, it's possible to use the PING command with the record route option; such as PING -r 1 and some site, the first one would be the router; or TRACERT, as mentioned by Stuart.
John Gray wrote:However his link to CMDnet (which looked like just the utility I wanted) fails, and I had some trouble tracking down a copy.

Running CMDnet at work gives the external IP address as 127.0.0.1, which doesn't fill me with much confidence that it will work at home...
Yep, I knew about the links to the CMDnet, that's why I didn't mention that tool, and I have not tried to find it and test it, but I wanted to point to Petri's page.

With VPN I don't know. Perhaps also could use the SNMP protocol, but solutions involving the router would depend on what kind of router, I guess.

Then there are other tools out there, such as this one:
WWIP (Watch WAN IP)
http://www.emc3.us/emc3ware/" onclick="window.open(this.href);return false;
It can monitor changes on the router's wlan page, using "Screen Scraping" techniques, i.e. the HTML source, :grin: and comparing it to the old address and being able to send e-mails etc. Req. .NET Framework 1; I don't know if it works if the router has a captcha image at the login, and I don't know about the remote management setting.
I just had to mention this, in my mind, odd approach.
But there are several other tools out there, and perhaps other solutions.
Byelingual    When you speak two languages but start losing vocabulary in both of them.

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Command line utility to get external IP address

Post by John Gray »

I've tried PING -r but all the websites I tried (about three!) don't accept PINGs, so no route information appeared.

The WWIP program looks exactly (at first glance) what I would like to do, but I was wondering about the security exposure, if any!

It will all depend on what results I get from home, on XP and Windows 7 64-bit...
John Gray

Venison is quiet deer, and quite dear.

User avatar
Argus
GoldLounger
Posts: 3081
Joined: 24 Jan 2010, 19:07

Re: Command line utility to get external IP address

Post by Argus »

Mmm, I don't know what kind of sites you tried with; obviously, at first, I sent some to some site over here, but found that it worked with for example BBC's etc. Anyhow, a simple PING relies on other services working, as you very well know.

And yes, security is obviously important.
Byelingual    When you speak two languages but start losing vocabulary in both of them.

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Command line utility to get external IP address

Post by John Gray »

StuartR wrote:Depending on your router, you may be able to get what you want from the DOS tracert command. This doesn't work with my router as it fails to respond to the ICMP ECHO requests.
No, nothing emerges from this, other than that Eileenslounge.com apparently is at kundenserver.de!

And Windows 7 doesn't seem to have a telnet command.

And I've tried several other web addresses, but they are not PINGable, so I suspect my router doesn't allow ICMP out.
John Gray

Venison is quiet deer, and quite dear.

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Command line utility to get external IP address

Post by John Gray »

When the VPN from home to work is started, all the following web addresses give the IP address of the VPN target, not my own external IP address...
http://whatismyip.com" onclick="window.open(this.href);return false;
http://whatismyipaddress.com" onclick="window.open(this.href);return false;
http://checkip.dyndns.org" onclick="window.open(this.href);return false;
http://checkip.dyndns.org:8245" onclick="window.open(this.href);return false;
http://checkip.org" onclick="window.open(this.href);return false;
http://www.ipaddresslocation.org" onclick="window.open(this.href);return false;
http://www.find-ip-address.org" onclick="window.open(this.href);return false;
http://showmyip.com" onclick="window.open(this.href);return false;
http://www.displaymyhostname.com/" onclick="window.open(this.href);return false;
as also
wget -q -O - http://whatismyip.com/automation/n09230945.asp" onclick="window.open(this.href);return false;

One of those says that "you don't appear to be using a proxy"...
John Gray

Venison is quiet deer, and quite dear.

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Command line utility to get external IP address

Post by John Gray »

I think I might have a slight clue as to what is going on.

When I start up the VPN on Windows 7 I notice that clicking on the "networking icon" in the notification area indicates that the VPN is active/connected but that "Network" has "No internet access".

Additionally, when the VPN is connected, then I am unable to use Outlook Web Access to the Exchange Server at work.

Does this mean that all my web browsing is being routed over the VPN by some magic and transparent-to-me mechanism? Or am I getting even deeper into the networking mire?
John Gray

Venison is quiet deer, and quite dear.

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Command line utility to get external IP address

Post by StuartR »

John Gray wrote:...Does this mean that all my web browsing is being routed over the VPN by some magic and transparent-to-me mechanism? Or am I getting even deeper into the networking mire?
This magic is called routing.

If you type

Code: Select all

route print
to a DOS command, you will see the routing table that your PC uses to decide which interface it should use for each outgoing destination.
StuartR