美文网首页
判断ipv6 /ipv4

判断ipv6 /ipv4

作者: UnityAsk | 来源:发表于2016-09-18 10:14 被阅读176次

    string[] GetLocalIpv4()
    {
    IPAddress[] localIPs;
    localIPs = Dns.GetHostAddresses(Dns.GetHostName());
    StringCollection IpCollection = new StringCollection();
    foreach (IPAddress ip in localIPs)
    {
    //根据AddressFamily判断是否为ipv4,如果是InterNetWorkV6则为ipv6
    if (ip.AddressFamily == AddressFamily.InterNetwork)
    IpCollection.Add(ip.ToString());
    }
    string[] IpArray = new string[IpCollection.Count];
    IpCollection.CopyTo(IpArray, 0);
    return IpArray;
    }

    相关文章

      网友评论

          本文标题:判断ipv6 /ipv4

          本文链接:https://www.haomeiwen.com/subject/xfgwettx.html