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.

I've seen this question, but it doesn't address my current issue (it's about getting the external IP address of the current machine):
Windows command that returns external IP

I'm on a network that has a number of external IP addresses. I need to determine the external address of an internal machine that may use a different external address. Obviously, I could go to a machine outside the network and ping it from there, but how do I do this from inside the network?

I would like this to be incorporated into an automated process, so a DOS command or PowerShell script would be preferred.

share|improve this question
1  
Isn't it set using NAT on your router? The machine isn't aware of any external address. Only router is –  Ashtray Sep 13 '13 at 15:24
    
@Ashtray Is it possible to do something like ping the server via another external server / service? –  p.s.w.g Sep 13 '13 at 15:35
1  
It would be easier to answer if we'd know what are you trying to achieve/test/whatever :) –  Ashtray Sep 13 '13 at 15:37
    
@Ashtray I want to automatically build a list of IP address(es) that a customer will need to access when we install a particular product on their machine. Some customers are behind a firewall, so we can't determine it from the machine we're installing on (we would already need to know which IP's need to be unblocked). Rather, I'd like our build server to generate the list dynamically by resolving the server names to external IP addresses. –  p.s.w.g Sep 13 '13 at 16:13

5 Answers 5

up vote 3 down vote accepted

I think the only way you're gonna do this is with external services. You can use the system.Net.WebClient Powershell library along with the website http://icanhazip.com, which returns nothing but your external IP address.

$obj = New-Object system.Net.WebClient;
$ip = $obj.downloadString("http://icanhazip.com")
share|improve this answer
    
How can I get this to return the IP address of another machine? –  p.s.w.g Sep 13 '13 at 15:52
1  
You'd have to execute it from THAT machine. Or, you could run Powershell on that machine remotely by using PsExec. technet.microsoft.com/en-us/sysinternals/bb897553.aspx –  trpt4him Sep 13 '13 at 15:54
    
I agree: you would need to be on the other machine in order to discover its external IP address, so the other question that you cited is relevant. –  Scott Sep 13 '13 at 16:27
2  
@barlop, the OP said there are multiple external IPs. Presumably different machines could have different external IPs. –  trpt4him Sep 13 '13 at 20:30
2  
Well, if you have a hostname that reliably points to that IP, then you can just use nslookup to get the IP. –  trpt4him Sep 13 '13 at 23:46

Edit: Scratch that, I got the gateway mixed up with the external IP. I was able to find this one though that has a bunch of good information in it.

I'm sure there has to be an easy way to do it locally but there are just too many variables.

How to get my external ip address over nat from the windows command line

share|improve this answer

If you can install programs on the other machine, an easy way would be to configure this machine to publish its IP address as a dns entry.

For example http://dyn.com/dns/ (not free) and http://www.noip.com/free/ appear to be two programs that provide this service.

For example, with dyn.com you can install a program which runs as a service on the other machine that will keep updating the dns entry for, as an example, yourname.dyndns.org.

If you want to know the current ip address, then you can just ping yourname.dyndns.org.

In some cases (eg accessing an webserver), you could use the name directly and never need to know the ip address.

share|improve this answer

ifconfig.me is a bit slow for me at the moment, but this works.

From commandlinefu

curl ifconfig.me

curl ifconfig.me/ip -> IP Adress
curl ifconfig.me/host -> Remote Host
curl ifconfig.me/ua ->User Agent
curl ifconfig.me/port -> Port

Another is

C:\>wget -O abc.a ifconfig.me/ip 2>nul & type abc.a

(obviously you can put that wget line in a bat file so effectively make a shortcut for it)

you have to download wget(from gnuwin32) or curl http://curl.haxx.se/download.html

share|improve this answer
    
as an alternative: ifcfg.me –  Eun Nov 28 at 11:37
    
@Eun the good thing with ifconfig.me/ip was it gave just the IP address no other data to grep. –  barlop Nov 28 at 11:48
    
Should work with ifcfg.me too, just do curl ifcfg.me, btw it also supports ftp, nslookup etc. –  Eun Nov 28 at 11:53
    
@Eun oh I see, it detects user agent so chrome returns an html page and curl - an ip. good find –  barlop Nov 28 at 12:52

I had similar problem so I wrote simple command line tool, you can download it here.

share|improve this answer
1  
If you read the comments to the accepted answer you'll notice that the this is not the answer the OP was looking for. –  Sander Steffann Jan 4 at 9:59

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.