我的方法获取的extern IP:它基本上返回的extern IPadressC#中使用的WebRequest需要很长时间
public static string Get_IP()
{
string url = "http://checkip.dyndns.org";
WebRequest req = WebRequest.Create(url);
WebResponse resp = req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
string response = sr.ReadToEnd().Trim();
string[] a = response.Split(':');
string a2 = a[1].Substring(1);
string[] a3 = a2.Split('<');
string a4 = a3[0];
return a4;
}
我不能明白,为什么我的方法需要很长的时间来加载IpAdress,有时它会立即回吧!
ps:我检查了我的互联网连接,它工作完美,我不认为它的连接速度问题!
谢谢!
http://stackoverflow.com/questions/11794413/get-endpoint-ip-from-url – Oluwafemi