public static bool TryGetLocalEndPoint(out IPEndPoint ipEndPoint)
{
try {
string localIP = string.Empty;
using (Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp))
{
socket.Connect("www.baidu.com", 80);
ipEndPoint = socket.LocalEndPoint as IPEndPoint;
return true;
}
}
catch(SocketException ex) {
ipEndPoint = null;
return false;
}
}
标签:return,socket,C#,ipEndPoint,本地,IP地址,string
From: https://www.cnblogs.com/dewxin/p/17518054.html