Exemplo n.º 1
0
        static void Info()
        {
            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();
            }
        }
Exemplo n.º 2
0
 static void Info()
 {
     foreach (NetworkInterface nic in IcsManager.GetAllIPv4Interfaces())
     {
         PrintNICInfo(nic);
         Console.WriteLine();
     }
     Status();
 }
Exemplo n.º 3
0
 private void RefreshConnections()
 {
     cbSharedConnection.Items.Clear();
     cbHomeConnection.Items.Clear();
     foreach (var nic in IcsManager.GetAllIPv4Interfaces())
     {
         AddNic(nic);
     }
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        private void RefreshStatus()
        {
            bool SharingEnabled = false;

            cbSharedConnection.Items.Clear();
            cbHomeConnection.Items.Clear();
            foreach (NetworkInterface nic in IcsManager.GetAllIPv4Interfaces())
            {
                ConnectionItem connItem = new ConnectionItem(nic);
                cbSharedConnection.Items.Add(connItem);
                cbHomeConnection.Items.Add(connItem);
                INetConnection netShareConnection = connItem.Connection;
                if (netShareConnection != null)
                {
                    INetSharingConfiguration config = IcsManager.GetConfiguration(netShareConnection);
                    if (config.SharingEnabled)
                    {
                        SharingEnabled = true;
                        switch (config.SharingConnectionType)
                        {
                        case tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PUBLIC:
                            cbSharedConnection.SelectedIndex = cbSharedConnection.Items.Count - 1;
                            break;

                        case tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PRIVATE:
                            cbHomeConnection.SelectedIndex = cbSharedConnection.Items.Count - 1;
                            break;
                        }
                    }
                }
            }
            this.ButtonApply.Enabled        = !SharingEnabled;
            this.buttonStopSharing.Enabled  = SharingEnabled;
            this.cbSharedConnection.Enabled = !SharingEnabled;
            this.cbHomeConnection.Enabled   = !SharingEnabled;
            cbHomeConnection_SelectedIndexChanged(null, null);
            cbSharedConnection_SelectedIndexChanged(null, null);
        }