- public static string GetIP()
- {
- string strAddr = "";
- try
- {
- string strHostName = System.Net.Dns.GetHostName();
- System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
- foreach (IPAddress _ipaddress in ipEntry.AddressList)
- {
- if (_ipaddress.AddressFamily.ToString().ToLower() == "internetwork")
- {
- strAddr = _ipaddress.ToString();
- break;
- }
- }
- Log.Debug(" IP:" + strAddr);
- }
- catch (System.Exception e)
- {
- Log.Error(" Get IP Address Error:" + e.Message);
- }
- return strAddr;
- }
C# 获取主机IP地址
最新推荐文章于 2024-01-16 09:51:46 发布