当前位置: 移动技术网 > IT编程>开发语言>c# > c#获取本机的IP地址的代码

c#获取本机的IP地址的代码

2019年07月18日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下: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;
}

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网