using System.Collections;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using UnityEngine;
using UnityEngine.UI;
public class test : MonoBehaviour
{
public Text tt01;
// Start is called before the first frame update
void Start()
{
GetIP();
}
// Update is called once per frame
void Update()
{
}
/// <summary>
/// 获取本机IP
/// </summary>
/// <param name="Addfam">要获取的IP类型</param>
/// <returns></returns>
public string GetIP()
{
string output = "";
foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
{
NetworkInterfaceType _type1 = NetworkInterfaceType.Wireless80211; //无线局域网适配器
if ((item.NetworkInterfaceType == _type1) && item.OperationalStatus == OperationalStatus.Up)
{
foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)
{
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
{
output = ip.Address.ToString();
tt01.text = output;
// Debug.Log("IP:" + output);
}
}
}
}
return output;
}
}
FR:徐海涛(hunk Xu)
QQ技术交流群:386476712