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 { /// /// Restituisce l'IP v4 locale dato uno degli ip machcina (anche IPV6) /// /// /// 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; } } }