External IP of Internal Server
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.
45 Answers
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 , which returns nothing but your external IP address.
$obj = New-Object system.Net.WebClient;
$ip = $obj.downloadString("") 8 ifconfig.me is a bit slow for me at the moment, but this works.
From commandlinefu
curl ifconfig.me
curl -> IP Adress
curl -> Remote Host
curl ->User Agent
curl -> PortAnother is
C:\>wget -O abc.a 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(a recent one is in/bundled with cygwin) or use curl
I'd add, that technically what you are finding is the IP of the external interface of your router / home router / NAT device. So the side of that device opposite to where your computer's plug into it. The side of that device that is facing the wall and connecting to your ISP through the wall. The IP of the network interface that is there.
4Edit: 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
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 (not free) and 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.
I had similar problem so I wrote simple command line tool, you can download OuterIP from sourceforge.
2