/// <summary>
/// 获取本机IP
/// </summary>
/// <returns></returns>
private string GetIP()
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adater in adapters)
{
if (adater.Supports(NetworkInterfaceComponent.IPv4))
{
UnicastIPAddressInformationCollection UniCast = adater.GetIPProperties().UnicastAddresses;
if (UniCast.Count > 0)
{
foreach (UnicastIPAddressInformation uni in UniCast)
{
if (uni.Address.AddressFamily == AddressFamily.InterNetwork)
{
Debug.Log(uni.Address.ToString());
return uni.Address.ToString();
}
}
}
}
}
return null;
}
网友评论