Ejemplo n.º 1
0
        //private string GetMacAddress()
        //{
        //    string macAddresses = string.Empty;
        //
        //    foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
        //    {
        //        if (nic.OperationalStatus == OperationalStatus.Up)
        //        {
        //            macAddresses += nic.GetPhysicalAddress().ToString();
        //            break;
        //        }
        //    }
        //    Console.WriteLine(macAddresses);
        //    return macAddresses;
        //}
        public static string GetLocalIPAddress()
        {
            var host = Dns.GetHostEntry(Dns.GetHostName());

            foreach (var ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    return(ip.ToString());
                }
            }
            throw new Exception("No network adapters with an IPv4 address in the system!");
        }