protected override void ProcessRecord()
        {
            var connectionToShare = IcsManager.FindConnectionByIdOrName(Shared_connection);

            if (connectionToShare == null)
            {
                WriteError(new ErrorRecord(new PSArgumentException("Connection not found"), "", ErrorCategory.InvalidArgument, Shared_connection));
                return;
            }
            var homeConnection = IcsManager.FindConnectionByIdOrName(Home_connection);

            if (homeConnection == null)
            {
                WriteError(new ErrorRecord(new PSArgumentException("Connection not found"), "", ErrorCategory.InvalidArgument, Home_connection));
                return;
            }

            var currentShare = IcsManager.GetCurrentlySharedConnections();

            if (currentShare.Exists)
            {
                WriteWarning("Internet Connection Sharing is already enabled: " + currentShare.ToString());
                if (!force)
                {
                    WriteError(new ErrorRecord(new PSInvalidOperationException("Please disable existing ICS if you want to enable it for other connections, or set the force flag to true"), "", ErrorCategory.InvalidOperation, null));
                    return;
                }
                Console.WriteLine("Sharing will be disabled first.");
            }

            IcsManager.ShareConnection(connectionToShare, homeConnection);
        }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
 protected override void ProcessRecord()
 {
     IcsManager.ShareConnection(null, null);
 }