c#获取本机的IP地址的代码
程序员文章站
2023-12-04 15:43:31
复制代码 代码如下:public static ipaddress gethostip(){ &nbs...
复制代码 代码如下:
public static ipaddress gethostip()
{
iphostentry ipe = dns.gethostentry(dns.gethostname());
ipaddress ip = ipe.addresslist[0];
return ip;
}
private string getipaddress()
{
string str;
string result = "";
string hostname = dns.gethostname();
ipaddress[] myip = dns.gethostaddresses(hostname);
foreach (ipaddress address in myip)
{
str = address.tostring();
for (int i = 0; i < str.length; i++)
{
if (str[i] >= '0' && str[i] <= '9' || str[i] == '.') result = str;
}
}
return result;
}
上一篇: 详解vue使用$http服务端收不到参数
下一篇: 广告显示判断