在C#中获取本地公网IP地址
发布时间
阅读量:
阅读量
C#怎样才能查找到本机在互联网上的公网IP地址?
对应的代码示例如下:
public static string GetextenalIP()
{
//获取外部IP
String url = "http://hijoyusers.joymeng.com:8100/test/getNameByOtherIp";
string IP = "未获取到外网ip";
try
{
//从网址中获取本机ip数据
System.Net.WebClient client = new System.Net.WebClient();
client.Encoding = System.Text.Encoding.Default;
string str = client.DownloadString(url);
client.Dispose();
if (!str.Equals("")) IP = str;
else IP = GetExtenalIpAddress_0();
}
catch (Ex
全部评论 (0)
还没有任何评论哟~
