« Apache HTTP Server 2.4.4 Released | Main | Apache Tomcat 7.0.39 Released »


Powershell Two-Liner to Get External IP

It has been a while since I've had a Windows machine to play with but I get requests from developers quite often who want to know the external IP a partner will see when one of our servers are accessing that partner's site. On Unix and Unix-like servers, you can just run curl ifconfig.me (assuming curl is installed) and you're done, (curl -x [protocol][proxy_server][:port] ifconfig.me if you need to declare an anonymous outbound proxy server).

Windows server administrators though don't seem to install curl on their servers too often but there is a very good chance Powershell will be installed on it. If you're looking for a way to grab your external IP from the command line on Windows, the following Powershell 3.0 two-liner will work, (it definitely works on Windows 8):

$resp = Invoke-WebRequest -Uri http://ifconfig.me/ip -Method Get
Write-Output $resp.ParsedHtml.body.innerHtml

If you need to declare an outbound proxy (which does not require authentication), add -Proxy [proxy_server][:port] after -Method Get. Save it in a new script named something like "Get-MyExtIP.ps1" and you are all set.

Yes, one could just fire up Internet Explorer from a Terminal Services session and go to one of those external IP sites but this is a powershell post. :)


TrackBack URL for this entry:

Listed below are links to weblogs that reference Powershell Two-Liner to Get External IP :