Example #1
0
        private void AddNic(NetworkInterface nic)
        {
            var connItem = new ConnectionItem(nic);

            cbSharedConnection.Items.Add(connItem);
            cbHomeConnection.Items.Add(connItem);
            var netShareConnection = connItem.Connection;

            if (netShareConnection != null)
            {
                var sc = IcsManager.GetConfiguration(netShareConnection);
                if (sc.SharingEnabled)
                {
                    switch (sc.SharingConnectionType)
                    {
                    case tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PUBLIC:
                        cbSharedConnection.SelectedIndex = cbSharedConnection.Items.Count - 1;
                        break;

                    case tagSHARINGCONNECTIONTYPE.ICSSHARINGTYPE_PRIVATE:
                        cbHomeConnection.SelectedIndex = cbSharedConnection.Items.Count - 1;
                        break;
                    }
                }
            }
        }
Example #2
0
        static bool EnableICS(string shared_uuid_or_name, string home_uuid_or_name)
        {
            var connectionToShare = IcsManager.FindConnectionByIdOrName(shared_uuid_or_name);

            if (connectionToShare == null)
            {
                throw new Exception(string.Format("Connection not found: {0}", shared_uuid_or_name));
            }
            var homeConnection = IcsManager.FindConnectionByIdOrName(home_uuid_or_name);

            if (homeConnection == null)
            {
                throw new Exception(string.Format("Connection not found: {0}", home_uuid_or_name));
            }

            var currentShare = IcsManager.GetCurrentlySharedConnections();

            if (currentShare.Exists)
            {
                Console.WriteLine("Internet Connection Sharing is already enabled:");
                Console.WriteLine(currentShare);
                Console.WriteLine("Sharing will be disabled first.");
            }
            IcsManager.ShareConnection(connectionToShare, homeConnection);
            return(Status());
        }
Example #3
0
        static void EnableICS(string shared, string home, bool force)
        {
            var connectionToShare = IcsManager.FindConnectionByIdOrName(shared);

            if (connectionToShare == null)
            {
                Console.WriteLine("Connection not found: {0}", shared);
                return;
            }
            var homeConnection = IcsManager.FindConnectionByIdOrName(home);

            if (homeConnection == null)
            {
                Console.WriteLine("Connection not found: {0}", home);
                return;
            }

            var currentShare = IcsManager.GetCurrentlySharedConnections();

            if (currentShare.Exists)
            {
                Console.WriteLine("Internet Connection Sharing is already enabled:");
                Console.WriteLine(currentShare);
                if (!force)
                {
                    Console.WriteLine("Please disable it if you want to configure sharing for other connections");
                    return;
                }
                Console.WriteLine("Sharing will be disabled first.");
            }

            IcsManager.ShareConnection(connectionToShare, homeConnection);
        }
Example #4
0
 private void IcsManagerForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (stopOnClose.Checked)
     {
         IcsManager.ShareConnection(null, null);
     }
 }
Example #5
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            switch (e.CloseReason)
            {
            case CloseReason.UserClosing:
                e.Cancel = true;
                break;
            }
            base.OnFormClosing(e);
            var yourcommand = "NETSH WLAN STOP HOSTEDNETWORK";
            var procStart   = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + yourcommand);

            procStart.CreateNoWindow         = true;
            procStart.RedirectStandardOutput = true;
            procStart.UseShellExecute        = false;
            var proc = new System.Diagnostics.Process();

            proc.StartInfo = procStart;
            proc.Start();
            checkBox1.Text = "Start";
            IcsManager.ShareConnection(null, null);
            RefreshConnections();
            var result = proc.StandardOutput.ReadToEnd();

            MessageBox.Show(result);
            textBox1.ReadOnly = false;
            textBox2.ReadOnly = false;
            button1.BackColor = Color.Red;
            button1.Text      = "Stopped";
            Environment.Exit(0);
        }
Example #6
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();
            }
        }
Example #7
0
 private void RefreshConnections()
 {
     cbSharedConnection.Items.Clear();
     cbHomeConnection.Items.Clear();
     foreach (var nic in IcsManager.GetAllIPv4Interfaces())
     {
         AddNic(nic);
     }
 }
Example #8
0
 static void Info()
 {
     foreach (NetworkInterface nic in IcsManager.GetAllIPv4Interfaces())
     {
         PrintNICInfo(nic);
         Console.WriteLine();
     }
     Status();
 }
Example #9
0
        static bool DisableICS()
        {
            var currentShare = IcsManager.GetCurrentlySharedConnections();

            if (currentShare.Exists)
            {
                IcsManager.ShareConnection(null, null);
            }
            return(!Status());
        }
Example #10
0
        /// <summary>
        /// Инициализирует экземпляр класса NetShareHost
        /// </summary>
        public NetShareHost()
        {
            _wlanManager = new WlanManager();
            _icsManager  = new IcsManager();

            _wlanManager.StationJoin          += _wlanManager_StationStateChange;
            _wlanManager.StationLeave         += _wlanManager_StationStateChange;
            _wlanManager.HostedNetworkStarted += _wlanManager_HostedNetworkStarted;
            _wlanManager.HostedNetworkStopped += _wlanManager_HostedNetworkStopped;
        }
Example #11
0
        static void DisableICS()
        {
            var currentShare = IcsManager.GetCurrentlySharedConnections();

            if (!currentShare.Exists)
            {
                Console.WriteLine("Internet Connection Sharing is already disabled");
                return;
            }
            Console.WriteLine("Internet Connection Sharing will be disabled:");
            Console.WriteLine(currentShare);
            IcsManager.ShareConnection(null, null);
        }
Example #12
0
        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = cfg.IniReadValue("SETTING", "SSID");
            textBox2.Text = cfg.IniReadValue("SETTING", "PASS");
            var yourcommand = "NETSH WLAN SET HOSTEDNETWORK MODE=ALLOW SSID=" + textBox1.Text + " KEY=" + textBox2.Text + "";
            var procStart   = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + yourcommand);

            procStart.CreateNoWindow         = true;
            procStart.RedirectStandardOutput = true;
            procStart.UseShellExecute        = false;
            var proc = new System.Diagnostics.Process();

            proc.StartInfo = procStart;
            proc.Start();
            proc           = new System.Diagnostics.Process();
            proc.StartInfo = procStart;
            proc.Start();
            yourcommand = "NETSH WLAN START HOSTEDNETWORK";
            procStart   = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + yourcommand);
            procStart.CreateNoWindow         = true;
            procStart.RedirectStandardOutput = true;
            procStart.UseShellExecute        = false;
            proc           = new System.Diagnostics.Process();
            proc.StartInfo = procStart;
            proc.Start();
            try
            {
                RefreshConnections();

                var sharedConnectionItem = cbSharedConnection.SelectedItem as ConnectionItem;
                var homeConnectionItem   = cbHomeConnection.SelectedItem as ConnectionItem;
                if ((sharedConnectionItem == null) || (homeConnectionItem == null))
                {
                    MessageBox.Show(@"Please select both connections.");
                    return;
                }
                if (sharedConnectionItem.Connection == homeConnectionItem.Connection)
                {
                    MessageBox.Show(@"Please select different connections.");
                    return;
                }
                IcsManager.ShareConnection(sharedConnectionItem.Connection, homeConnectionItem.Connection);
                RefreshConnections();
            }
            catch
            { }
        }
Example #13
0
        private void ButtonApply_Click(object sender, EventArgs e)
        {
            var sharedConnectionItem = cbSharedConnection.SelectedItem as ConnectionItem;
            var homeConnectionItem   = cbHomeConnection.SelectedItem as ConnectionItem;

            if ((sharedConnectionItem == null) || (homeConnectionItem == null))
            {
                MessageBox.Show(@"Please select both connections.");
                return;
            }
            if (sharedConnectionItem.Connection == homeConnectionItem.Connection)
            {
                MessageBox.Show(@"Please select different connections.");
                return;
            }
            IcsManager.ShareConnection(sharedConnectionItem.Connection, homeConnectionItem.Connection);
            RefreshConnections();
        }
Example #14
0
        public bool setIP(string ip)
        {
            Trace.TraceInformation("Interface IP Changing");
            for (int i = 0; i < 5; i++)
            {
                if (IcsManager.setIpWMI(connectionGuid, ip, "255.255.255.0"))
                {
                    Trace.TraceInformation("Interface IP Changed");
                    break;
                }
                else
                {
                    Trace.TraceInformation("Interface IP Change failed");
                }
                Thread.Sleep(2000);
            }
            string          trimmedIp      = ip.TrimEnd("0123456789".ToCharArray());
            InternetAddress privateAddress = InternetAddress.Parse(ip);

            dhcpManager.DhcpInterfaceAddress = IPAddress.Parse(ip);
            dhcpManager.StartAddress         = InternetAddress.Parse(trimmedIp + "1");
            dhcpManager.EndAddress           = InternetAddress.Parse(trimmedIp + "255");
            dhcpManager.Subnet  = InternetAddress.Parse("255.255.255.0");
            dhcpManager.Gateway = privateAddress;
            dhcpManager.DnsServers.Add(privateAddress);
            for (int i = 1; i < 5; i++)
            {
                try {
                    Socket sock = dhcpManager.configureSocket();
                    sock.Close();
                    dhcpManager.Start();
                    return(true);
                } catch (SocketException e) {
                    if (e.ErrorCode == 10049)
                    {
                        Trace.TraceInformation("Interface IP waiting for ready.");
                        dhcpManager.Stop();
                        Thread.Sleep(2000);
                    }
                }
            }
            return(false);
        }
Example #15
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);
        }
Example #16
0
        public FrmMain()
        {
            InitializeComponent();

            dgvClients.AutoGenerateColumns = false;

            _wlnMgr     = new WlanManager();
            _icsMgr     = new IcsManager();
            _frmSharing = new FrmSharingManager();

            //监听虚拟路由状态的改变
            _wlnMgr.StationJoin += StationChanged;
            _wlnMgr.StationJoin += (_s, _e) => {
                ntfyDock.ShowBalloonTip(500, "", "发现客户端加入连接", ToolTipIcon.Info);
            };
            _wlnMgr.StationLeave         += StationChanged;
            _wlnMgr.StationStateChange   += StationChanged;
            _wlnMgr.HostedNetworkStarted += HostedNetworkStateChanged;
            _wlnMgr.HostedNetworkStarted += StationChanged;
            _wlnMgr.HostedNetworkStopped += HostedNetworkStateChanged;
            _wlnMgr.HostedNetworkStopped += StationChanged;
        }
Example #17
0
 void networkAddressChanged()
 {
     if (shouldStart_)
     {
         if (!icsManager.IsPublicConnected())
         {
             publicConnected_ = false;
         }
         else
         if (!publicConnected_)
         {
             publicConnected_ = true;
             events.put(SOFTEVENT.INTSTOP, 0);
             events.put(SOFTEVENT.TESTPRIVATE, 0);
         }
         else
         {
             if (state_ == getawayState.StartingIP)
             {
                 events.put(SOFTEVENT.RENEWIP, 0);
                 return;
             }
             if (state_ != getawayState.Started)
             {
                 return;
             }
             var currentPrivateConnection = IcsManager.getWMI(privateManager.connectionGuid);
             if (currentPrivateConnection != null)
             {
                 string[] addresses = (string[])currentPrivateConnection["IPAddress"];
                 if (!addresses[0].Equals(GetIP()))
                 {
                     Trace.TraceInformation("Private network address changed to:" + addresses[0]);
                     events.put(SOFTEVENT.RENEWIP, 0);
                 }
             }
         }
     }
 }
Example #18
0
        private void ButtonApply_Click(object sender, EventArgs e)
        {
            Infos = "ICSManager: applying settings";
            var sharedConnectionItem = cbSharedConnection.SelectedItem as ConnectionItem;
            var homeConnectionItem   = cbHomeConnection.SelectedItem as ConnectionItem;

            if ((sharedConnectionItem == null) || (homeConnectionItem == null))
            {
                MessageBox.Show(@"Please select both connections.");
                return;
            }
            if (sharedConnectionItem.Connection == homeConnectionItem.Connection)
            {
                MessageBox.Show(@"Please select different connections.");
                return;
            }
            IcsManager.ShareConnection(sharedConnectionItem.Connection, homeConnectionItem.Connection);
            RefreshConnections();
            Infos      = "ICSManager: refresh connections";
            Infos      = "ICSManager: done";
            ICSApplied = true;
        }
Example #19
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);
        }
Example #20
0
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                //startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

                if (checkBox1.Checked)
                {
                    var sharedConnectionItem = cbSharedConnection.SelectedItem as ConnectionItem;
                    var homeConnectionItem   = cbHomeConnection.SelectedItem as ConnectionItem;
                    if ((sharedConnectionItem == null) || (homeConnectionItem == null))
                    {
                        MessageBox.Show(@"Please select both connections.");
                        return;
                    }
                    if (sharedConnectionItem.Connection == homeConnectionItem.Connection)
                    {
                        MessageBox.Show(@"Please select different connections.");
                        return;
                    }
                    IcsManager.ShareConnection(sharedConnectionItem.Connection, homeConnectionItem.Connection);
                    RefreshConnections();

                    /*
                     * startInfo.FileName = "cmd.exe";
                     * //startInfo.Arguments = "NETSH WLAN SHOW DRIVERS";
                     * startInfo.Arguments = "NETSH WLAN SET HOSTEDNETWORK MODE=ALLOW SSID=" + textBox1.Text + " KEY=" + textBox2.Text + "";
                     * //startInfo.Arguments = "NETSH WLAN START HOSTEDNETWORK";
                     * process.StartInfo = startInfo;
                     * process.Start();
                     * //StreamWriter inputStream = shellProcess.StandardInput;
                     * //send command to cmd prompt and wait for command to execute with thread sleep
                     * //inputStream.WriteLine("echo CMD just received input");
                     * //inputStream.Flush();
                     */
                    var yourcommand = "NETSH WLAN SET HOSTEDNETWORK MODE=ALLOW SSID=" + textBox1.Text + " KEY=" + textBox2.Text + "";
                    var procStart   = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + yourcommand);
                    procStart.CreateNoWindow         = true;
                    procStart.RedirectStandardOutput = true;
                    procStart.UseShellExecute        = false;

                    var proc = new System.Diagnostics.Process();
                    proc.StartInfo = procStart;
                    proc.Start();
                    yourcommand = "NETSH WLAN START HOSTEDNETWORK";
                    procStart   = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + yourcommand);
                    procStart.CreateNoWindow         = true;
                    procStart.RedirectStandardOutput = true;
                    procStart.UseShellExecute        = false;

                    proc           = new System.Diagnostics.Process();
                    proc.StartInfo = procStart;
                    proc.Start();
                    var result = proc.StandardOutput.ReadToEnd();
                    MessageBox.Show(result);
                    checkBox1.Text    = "Stop";
                    textBox1.ReadOnly = true;
                    textBox2.ReadOnly = true;
                    button1.BackColor = Color.Lime;
                    button1.Text      = "Working";
                }
                else
                {
                    var yourcommand = "NETSH WLAN STOP HOSTEDNETWORK";
                    var procStart   = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + yourcommand);
                    procStart.CreateNoWindow         = true;
                    procStart.RedirectStandardOutput = true;
                    procStart.UseShellExecute        = false;
                    var proc = new System.Diagnostics.Process();
                    proc.StartInfo = procStart;
                    proc.Start();
                    checkBox1.Text = "Start";
                    IcsManager.ShareConnection(null, null);
                    RefreshConnections();
                    var result = proc.StandardOutput.ReadToEnd();
                    MessageBox.Show(result);
                    textBox1.ReadOnly = false;
                    textBox2.ReadOnly = false;
                    button1.BackColor = Color.Red;
                    button1.Text      = "Stopped";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #21
0
        private void ConnectIcs()
        {
            if (connectionComboBox.SelectedItem.ToString() == "No connection Avilable!")
            {
                StatusLbl.Text      = "Status: Hotspot started without ICS!";
                startButton.Text    = "&Stop";
                startButton.Enabled = true;
            }
            else
            {
                StatusLbl.Text = "Status: Trying to create ICS with " + connectionComboBox.SelectedItem.ToString() + ".";

                //------------------------------------------------------------------------------------------------------
                ManagementScope          IcsVirtualAdapterScope    = new ManagementScope();
                SelectQuery              IcsVirtualAdapterQuery    = new SelectQuery("Win32_NetworkAdapter", "Description=\"Microsoft Hosted Network Virtual Adapter\"");
                ManagementObjectSearcher IcsVirtualAdapterSearcher = new ManagementObjectSearcher(IcsVirtualAdapterScope, IcsVirtualAdapterQuery);
                //Dim IcsVirtualAdapterIdArray As New ComboBox

                try
                {
                    foreach (ManagementObject IcsVirtualAdapter in IcsVirtualAdapterSearcher.Get())
                    {
                        string IcsVirtualAdapterId = IcsVirtualAdapter["NetConnectionID"].ToString();
                        MainModule.IcsVirtualAdapterIdArray.Items.Add(IcsVirtualAdapterId);
                    }
                }
                catch
                {
                }

                if (MainModule.IcsVirtualAdapterIdArray.Items.Count > 1)
                {
                    VirtualAdapterSelectionDialog.DefaultInstance.ShowDialog();
                }
                else
                {
                    MainModule.IcsVirtualAdapterIdArray.SelectedIndex = 0;
                    MainModule.IcsVirtualAdapterId = MainModule.IcsVirtualAdapterIdArray.SelectedItem.ToString();
                }

                MainModule.IcsVirtualAdapterIdArray.Items.Clear();
                StatusLbl.Text = "Status: Selected virtual adapter: " + MainModule.IcsVirtualAdapterId + ".";
                //------------------------------------------------------------------------------------------------------

                try
                {
                    IcsManager.ShareConnection(IcsManager.GetConnectionByName(connectionComboBox.SelectedItem.ToString()), IcsManager.GetConnectionByName(MainModule.IcsVirtualAdapterId));
                    StatusLbl.Text      = "Status: Shared internet from " + connectionComboBox.SelectedItem.ToString() + " to " + MainModule.IcsVirtualAdapterId.ToString() + ".";
                    startButton.Text    = "&Stop";
                    startButton.Enabled = true;
                }
                catch
                {
                    StatusLbl.Text = "Status: Network shell busy, retrying ICS with " + connectionComboBox.SelectedItem.ToString() + ".";
                    //startButton.Text = "&Stop"
                    //startButton.Enabled = True
                    System.Threading.Thread.Sleep(1000);
                    ConnectIcs();
                }
            }
        }
Example #22
0
        private void DisconnectFunction()
        {
            startButton.Enabled = false;

            StatusLbl.Text = "Status: Trying to stop hotspot!";
            TrayStoppingStatus();

            IcsManager.ShareConnection(null, null);

            //Dim SysPath As String
            //SysPath = Environment.GetFolderPath(Environment.SpecialFolder.System)

            //Dim CommandSeperator As String
            //CommandSeperator = "&&"

            if (System.IO.File.Exists(SysPath + "\\netsh.exe"))
            {
                var ConnectionProcess = new Process();
                ConnectionProcess.StartInfo.FileName               = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\cmd.exe";
                ConnectionProcess.StartInfo.Arguments              = "/k echo off" + CommandSeperator + SysPath + "\\netsh.exe  wlan stop hostednetwork";
                ConnectionProcess.StartInfo.UseShellExecute        = false;
                ConnectionProcess.StartInfo.CreateNoWindow         = true;
                ConnectionProcess.StartInfo.RedirectStandardOutput = true;
                ConnectionProcess.StartInfo.RedirectStandardError  = true;
                ConnectionProcess.Start();
                ConnectionProcess.WaitForExit(4000);
                if (!ConnectionProcess.HasExited)
                {
                    ConnectionProcess.Kill();
                    System.IO.StreamReader SuccessOutPut = ConnectionProcess.StandardOutput;
                    System.IO.StreamReader ErrorOutPut   = ConnectionProcess.StandardError;
                    string ProcessSuccess = null;
                    string ProcessError   = null;
                    ProcessSuccess = SuccessOutPut.ReadToEnd();
                    ProcessError   = ErrorOutPut.ReadToEnd();
                    if (string.IsNullOrEmpty(ProcessError))
                    {
                        if (ProcessSuccess.Contains("The hosted network stopped"))
                        {
                            StatusLbl.Text = "Status: Hotspot stopped!";
                            EnableUserInterface();
                            IcsRefreshThread.RunWorkerAsync();
                            startButton.Text    = "&Start";
                            startButton.Enabled = true;
                            TrayStoppedStatus();
                        }
                    }
                    else
                    {
                        EnableUserInterface();
                        MessageBox.Show(ProcessError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    SuccessOutPut.Close();
                    ErrorOutPut.Close();
                    ConnectionProcess.Close();
                }
            }
            else
            {
                MessageBox.Show("netsh.exe Not found!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #23
0
 public VirtualRouterHost()
 {
     this.wlanManager = new WlanManager();
     this.icsManager  = new IcsManager();
 }
Example #24
0
        void events_processor(object sender, softEventQueue <SOFTEVENT> .EventType e)
        {
            switch (e.ev)
            {
            case SOFTEVENT.LOAD:
                this.icsManager = new IcsManager();
                state_          = getawayState.Idle;
                shouldStart_    = false;
                privateManager  = new privateNetManager();
                events.put(SOFTEVENT.LOADINIT, 0);
                break;

            case SOFTEVENT.LOADINIT:
                try {
                    privateManager.init();
                } catch {
                    startTimer();
                    break;
                }
                events.put(SOFTEVENT.LOAD_SAVED_STATE, 0);
                NetworkChange.NetworkAddressChanged      += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
                NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
                privateManager.networkAvailable          += new EventHandler(privateManager_networkAvailable);
                privateManager.networkUnavailable        += new EventHandler(privateManager_networkUnavailable);
                break;

            case SOFTEVENT.LOAD_SAVED_STATE:
                LoadConfig();
                if (shouldStart_)
                {
                    Start();
                }
                break;

            case SOFTEVENT.NETWORKADDRESSCHANGED:
                networkAddressChanged();
                break;

            case SOFTEVENT.STARTINIT:
                privateManager.enable();
                startTimer();
                break;

            case SOFTEVENT.RENEWIP:
                reNewIp();
                startTimer();
                break;

            case SOFTEVENT.UPDATECONNECTIONS:
                icsManager.updateConnections();
                break;

            case SOFTEVENT.RESTARTPRIVATE:
                intStop();
                if (shouldStart_)
                {
                    privateManager.enable();
                }
                break;

            case SOFTEVENT.TESTPRIVATE:
                testPrivateConnected();
                break;

            case SOFTEVENT.FIREROUTESTART:
                watchDog.Change(Timeout.Infinite, Timeout.Infinite);
                if (OnRouterStart != null)
                {
                    OnRouterStart(this, null);
                }
                break;

            case SOFTEVENT.INTSTOP:
                intStop();
                break;
            }
        }
Example #25
0
 private void buttonStopSharing_Click(object sender, EventArgs e)
 {
     IcsManager.ShareConnection(null, null);
     RefreshConnections();
 }