de7e742731
- aggiunta nuova path e rename
47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Sockets;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EgwCoreLib.Razor.Data
|
|
{
|
|
public class IpUtils
|
|
{
|
|
/// <summary>
|
|
/// Restituisce l'IP v4 locale dato uno degli ip machcina (anche IPV6)
|
|
/// </summary>
|
|
/// <param name="firstIp"></param>
|
|
/// <returns></returns>
|
|
public static string getLocalIpv4(string firstIp)
|
|
{
|
|
string devIp = firstIp;
|
|
IPAddress clientIP = IPAddress.Parse(devIp);
|
|
try
|
|
{
|
|
IPHostEntry GetIPHost = Dns.GetHostEntry(clientIP);
|
|
if (GetIPHost != null)
|
|
{
|
|
// se trovo + di 1 ip cerco il primo NON IPV6...
|
|
if (GetIPHost.AddressList.Count() > 1)
|
|
{
|
|
foreach (IPAddress item in GetIPHost.AddressList)
|
|
{
|
|
if (item.AddressFamily == AddressFamily.InterNetwork)
|
|
{
|
|
devIp = item.ToString();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
return devIp;
|
|
}
|
|
}
|
|
}
|