软件编程
位置:首页>> 软件编程>> C#编程>> c#获取本机的IP地址的代码

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

  发布时间:2021-08-21 08:37:07 

标签:c#,IP,地址


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;
}

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com