public static void GetIP() { /* * foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) * { * if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) * { * foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses) * { * if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) * { * Console.WriteLine("\t" + ni.Name.ToString()); * Console.WriteLine("\t" + ip.Address.ToString()); * Console.WriteLine("\t" + ip.IPv4Mask.ToString()); * Console.WriteLine("\tSTATUS: " + ni.OperationalStatus.ToString().ToUpper() + "\n"); } * } * } * }*/ NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in adapters) { IPInterfaceProperties adapterProperties = adapter.GetIPProperties(); GatewayIPAddressInformationCollection addresses = adapterProperties.GatewayAddresses; if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet) { foreach (UnicastIPAddressInformation ip in adapter.GetIPProperties().UnicastAddresses) { if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { Console.WriteLine("\t" + adapter.Name.ToString()); Console.WriteLine("\t" + ip.Address.ToString()); Console.WriteLine("\t" + ip.IPv4Mask.ToString()); Console.WriteLine("\t" + addresses.ToString()); Console.WriteLine("\tSTATUS: " + adapter.OperationalStatus.ToString().ToUpper() + "\n"); } } } } }