借用搜狐的接口實現獲取公網IP
public string GetIP()
{
string tempip = "";
WebRequest request = WebRequest.Create("http://pv.sohu.com/cityjson?ie=utf-8");
request.Timeout = 10000;
WebResponse response = request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
string htmlinfo = sr.ReadToEnd();
Regex r = new Regex("((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)\\.){3}(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|[1-9])", RegexOptions.None);
Match mc = r.Match(htmlinfo);
tempip = mc.Groups[0].Value;
resStream.Close();
sr.Close();
return tempip;
}