public static GetHostEntry ( |
||
address | ||
return |
private static IPAddress Resolve(string hostName) { IPHostEntry he = Dns.GetHostEntry(hostName); if (he.AddressList.Length < 1) { throw new ApplicationException("IPHostEntry.AdressList is empty."); } return(he.AddressList[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!"); }