NetworkInterface: GetIPProperties : NetworkInterface « Network « C# / C Sharp






NetworkInterface: GetIPProperties

 
using System;
using System.Net.NetworkInformation;

class MainClass {
    static void Main() {
        if (NetworkInterface.GetIsNetworkAvailable()) {
            NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface ni in interfaces) {
                foreach (UnicastIPAddressInformation addr in ni.GetIPProperties().UnicastAddresses) {
                    Console.WriteLine("         - {0} (lease expires {1})", addr.Address, DateTime.Now + new TimeSpan(0, 0, (int)addr.DhcpLeaseLifetime));
                }
            }
        } else {
            Console.WriteLine("No network available.");
        }
    }
}

 








Related examples in the same category

1.NetworkInterface: GetIPv4Statistics
2.NetworkInterface: GetPhysicalAddress
3.NetworkInterface: OperationalStatus
4.NetworkInterface: NetworkAvailabilityChanged event
5.NetworkInterface:NetworkAddressChanged event
6.NetworkInterface: GetAllNetworkInterfaces
7.NetworkInterface: Name
8.NetworkInterface: Description
9.NetworkInterface: Id
10.NetworkInterface: NetworkInterfaceType
11.NetworkInterface: Speed