Thursday, April 28, 2011

How to get public IP using Powershell

   1: $r = [System.Net.WebRequest]::Create("http://automation.whatismyip.com/n09230945.asp")
   2: $resp = $r.GetResponse()
   3: $reqstream = $resp.GetResponseStream()
   4: $sr = new-object System.IO.StreamReader $reqstream
   5: $result = $sr.ReadToEnd()
   6: write-host $result
That scrips makes a HTTP GET to a page in http://www.whatismyip.com to find out the public IP address of the computer running the script.
Spanish Version

1 comment:

cabruins said...

Link has changed to:

http://automation.whatismyip.com/n09230945.asp