首页 > 编程语言 >C# 获取本地IP

C# 获取本地IP

时间:2022-12-09 13:45:56浏览次数:39  
标签:endPoint socket C# IP localIP 本地 Socket string

public string GetLocalIPStr()
{
    string localIP = string.Empty;
    using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
    {
        socket.Connect("8.8.8.8", 65530);
        IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
        localIP = endPoint.Address.ToString();
    }

    return localIP;
}

标签:endPoint,socket,C#,IP,localIP,本地,Socket,string
From: https://www.cnblogs.com/huvjie/p/16968699.html

相关文章