protected override void ProcessRecord()
        {
            foreach (var nic in IcsManager.GetAllIPv4Interfaces())
            {
                Console.WriteLine(
                    "Name .......... : {0}", nic.Name);
                Console.WriteLine(
                    "GUID .......... : {0}", nic.Id);
                Console.WriteLine(
                    "Status ........ : {0}", nic.OperationalStatus);

                Console.WriteLine(
                    "InterfaceType . : {0}", nic.NetworkInterfaceType);

                if (nic.OperationalStatus == OperationalStatus.Up)
                {
                    var ipprops = nic.GetIPProperties();
                    foreach (var a in ipprops.UnicastAddresses)
                    {
                        if (a.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            Console.WriteLine(
                                "Unicast address : {0}/{1}", a.Address, a.IPv4Mask);
                        }
                    }
                    foreach (var a in ipprops.GatewayAddresses)
                    {
                        Console.WriteLine(
                            "Gateway ....... : {0}", a.Address);
                    }
                }
                try
                {
                    var connection = IcsManager.GetConnectionById(nic.Id);
                    if (connection != null)
                    {
                        var props = IcsManager.GetProperties(connection);
                        Console.WriteLine(
                            "Device ........ : {0}", props.DeviceName);
                        var sc = IcsManager.GetConfiguration(connection);
                        if (sc.SharingEnabled)
                        {
                            Console.WriteLine(
                                "SharingType ... : {0}", sc.SharingConnectionType);
                        }
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    Console.WriteLine("Please run this program with Admin rights to see all properties");
                }
                catch (NotImplementedException e)
                {
                    Console.WriteLine("This feature is not supported on your operating system.");
                    Console.WriteLine(e.StackTrace);
                }
                Console.WriteLine();
            }
        }
示例#2
0
 protected override void ProcessRecord()
 {
     foreach (var nic in IcsManager.GetIPv4EthernetAndWirelessInterfaces())
     {
         var connection    = IcsManager.GetConnectionById(nic.Id);
         var properties    = IcsManager.GetProperties(connection);
         var configuration = IcsManager.GetConfiguration(connection);
         var record        = new { Name = nic.Name, GUID = nic.Id, MAC = nic.GetPhysicalAddress(), Description = nic.Description, SharingEnabled = configuration.SharingEnabled, NetworkAdapter = nic, Configuration = configuration, Properties = properties };
         WriteObject(record);
     }
 }