如何获得公共互联网IP? [英] How to get Public Internet IP?
本文介绍了如何获得公共互联网IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过C#代码获取我的公共IP地址?
How can I get my public IP address through C# code?
推荐答案
您将需要询问另一台服务器来告诉您您的公共地址.也许这会对您有帮助:
Hi,
You will need to ask another server to tell you your public address. Maybe this will help you:
public string getPublicIP()
{
string direction;
WebRequest request = WebRequest.Create("http://checkip.dyndns.org/");
WebResponse response = request.GetResponse();
StreamReader stream = new StreamReader(response.GetResponseStream());
direction = stream.ReadToEnd();
stream.Close();
response.Close();
//Search for the ip in the html
int first = direction.IndexOf("Address: ") + 9;
int last = direction.LastIndexOf("</body>");
direction = direction.Substring(first, last - first);
return direction;
}
这篇关于如何获得公共互联网IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文