using Sln.Iot.Serilog; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; namespace Sln.Iot.Common { public class GetLocalIP { public static string GetLocalIPAddress() { Dictionary localIP = new Dictionary(); try { string name = Dns.GetHostName(); IPAddress[] ipadrlist = Dns.GetHostAddresses(name); foreach (IPAddress ipa in ipadrlist) { if (ipa.AddressFamily == AddressFamily.InterNetwork) { Console.WriteLine(ipa.ToString()); //localIP.Add(ipa.) } } return ""; } catch (Exception ex) { SerilogHelper.Instance.Error("获取本地IP地址异常", ex); return string.Empty; } } } }