08-31-2010, 12:33 PM
This is poorly written but does the job. Didn't bother with timeouts, which probably need to be added. And there probably is a faster way of getting your IP but this is the fastest way I could think of.
Imports:
Code:
Usage:
Imports:
Code:
using System.Net;
using System.IO;
Code:
Code:
static string IP()
{
//http://www.whatismyip.com/automation/n09230945.asp
HttpWebRequest WhatIsMyIP_Request = (HttpWebRequest)HttpWebRequest.Create("http://www.whatismyip.com/automation/n09230945.asp");
HttpWebResponse WhatIsMyIP_Response = (HttpWebResponse)WhatIsMyIP_Request.GetResponse();
StreamReader WhatIsMyIP_Source = new StreamReader(WhatIsMyIP_Response.GetResponseStream());
return WhatIsMyIP_Source.ReadToEnd();
}
Usage:
Code:
Console.WriteLine(IP());