You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
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<string, string> localIP = new Dictionary<string, string>();
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|