コード例 #1
0
        static void Info()
        {
            foreach (var nic in IcsManager.GetIPv4EthernetAndWirelessInterfaces())
            {
                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
        static bool Status()
        {
            NetworkInterface shared  = null;
            NetworkInterface home    = null;
            bool             sharing = false;

            foreach (NetworkInterface nic in IcsManager.GetAllIPv4Interfaces())
            {
                var connection = IcsManager.GetConnectionById(nic.Id);
                if (connection != null)
                {
                    var props = IcsManager.GetProperties(connection);
                    var sc    = IcsManager.GetConfiguration(connection);
                    if (sc.SharingEnabled)
                    {
                        if (sc.SharingConnectionType == NETCONLib.tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PRIVATE)
                        {
                            home    = nic;
                            sharing = true;
                        }
                        else if (sc.SharingConnectionType == NETCONLib.tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PUBLIC)
                        {
                            shared  = nic;
                            sharing = true;
                        }
                    }
                }
            }
            if (!sharing)
            {
                Console.WriteLine("ICS is DISABLED");
            }
            else
            {
                Console.WriteLine("ICS is ENABLED");
                Console.WriteLine("*** SHARED connection: ");
                PrintNICInfo(shared);
                Console.WriteLine("*** HOME connection: ");
                PrintNICInfo(home);
            }
            return(sharing);
        }