粘贴直接就能用
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;
}