private
IPAddress GetLocalHost()
... {
try
...{
WebClient wClient = new WebClient();
byte[] byteRecv = wClient.DownloadData("http://www.ip138.com/");
string strRecv = Encoding.GetEncoding("GB2312").GetString(byteRecv);
string pattern = @"(((d{1,2})|(1d{2})|(2[0-4]d)|(25[0-5])).){3}((d{1,2})|(1d{2})|(2[0-4]d)|(25[0-5]))";
string localHost = Regex.Match(strRecv, pattern).ToString();
return IPAddress.Parse(localHost);
}
catch (Exception exx)
...{
System.Diagnostics.Trace.WriteLine("Exception Occured while Running GetLocalHost--> " + exx.Message);
return IPAddress.Parse("127.0.0.1");
}
}
... {
try
...{
WebClient wClient = new WebClient();
byte[] byteRecv = wClient.DownloadData("http://www.ip138.com/");
string strRecv = Encoding.GetEncoding("GB2312").GetString(byteRecv);
string pattern = @"(((d{1,2})|(1d{2})|(2[0-4]d)|(25[0-5])).){3}((d{1,2})|(1d{2})|(2[0-4]d)|(25[0-5]))";
string localHost = Regex.Match(strRecv, pattern).ToString();
return IPAddress.Parse(localHost);
}
catch (Exception exx)
...{
System.Diagnostics.Trace.WriteLine("Exception Occured while Running GetLocalHost--> " + exx.Message);
return IPAddress.Parse("127.0.0.1");
}
}