using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
namespace FXBVT_Team.CheckFilePath
{
public class IPNetworking
{
public static string GetIP4Address(string hostAddress)
{
string IP4Address = String.Empty;
foreach (IPAddress IPA in Dns.GetHostAddresses(hostAddress))
{
if (IPA.AddressFamily.ToString() == "InterNetwork")
{
IP4Address = IPA.ToString();
break;
}
}
if (IP4Address != String.Empty)
{
return IP4Address;
}
foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (IPA.AddressFamily.ToString() == "InterNetwork")
{
IP4Address = IPA.ToString();
break;
}
}
return IP4Address;
}
}
}
如何通过hostname获取已使用IPv6协议的IPv4地址
最新推荐文章于 2023-08-27 22:43:53 发布