Ejemplo n.º 1
0
 private void UpdateInterfaceList(object sender, EventArgs e)
 {
     NetIList.Items.Clear();
     NetInterfaceList.Clear();
     NetIList.DropDownStyle = ComboBoxStyle.DropDownList;
     //foreach (NetworkInterfaceInfo NetITFInfo in ICSRouter.GetNetworkInterfaces())
     foreach (NetworkInterfaceInfo NetITFInfo in ICSRouter.GetNetworkConnectionsInfo())
     {
         if (NetITFInfo.InterfaceGuid.Equals(WlanMgr.HostedNetworkGuid))
         {
             continue;
         }
         NetIList.DropDownWidth = 300;
         NetIList.Items.Add($"{NetITFInfo.DeviceName} ({NetITFInfo.DeviceDescription})");
         NetInterfaceList.Add(NetITFInfo);
     }
     if (NetIList.Items.Count <= 0)
     {
         Invoke(new Action(() =>
                           { IPvXBox.ForeColor = System.Drawing.Color.Black; IPvXBox.Text = $"No NIC selected"; }));
         MessageBox.Show("There is no network interface connected to a network", Text,
                         MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         Invoke(new Action(() =>
                           { IPvXBox.ForeColor = System.Drawing.Color.Black; IPvXBox.Text = $"No NIC selected"; }));
     }
 }
Ejemplo n.º 2
0
 private void OnMainFormClosing(object sender, FormClosingEventArgs e)
 {
     if (!(WlanMgr is null))
     {
         _ = IPhlpapi.FlushIpNetTable(WlanMgr.HostedNetworkGuid);
         ICSRouter.StopSharing();
         _ = WlanMgr.ForceStop();
     }
 }
Ejemplo n.º 3
0
        internal void StartHostedNetwork(string ssid, string key, Guid InterfaceGuid)
        {
            WLAN_HOSTED_NETWORK_REASON WlanHnkReason;

            WlanMgr.QueryConnectionSettings(out string SSID, out uint MaxNumberOfPeers);
            WlanMgr.SetConnectionSettings(ssid, MaxNumberOfPeers);
            WlanMgr.SetSecondaryKey(key, true, true);

            switch (WlanMgr.HostedNetworkState)
            {
            case WLAN_HOSTED_NETWORK_STATE.wlan_hosted_network_active:

                try
                {
                    IPhlpapi.FlushIpNetTable(WlanMgr.HostedNetworkGuid);
                    ICSRouter.StopSharing();
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"{ex.Message}", Text,
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                finally
                {
                    _ = WlanMgr.ForceStop();
                }

                break;

            case WLAN_HOSTED_NETWORK_STATE.wlan_hosted_network_unavailable:

                if (!(Advapi32.GetPrivileges() && WlanMgr.AllowHostedNetwork(true)))
                {
                    MessageBox.Show("The hosted network couldn't be started.",
                                    Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    break;
                }
                WlanHnkReason = WlanMgr.ForceStart();
                if (WlanHnkReason != 0)
                {
                    MessageBox.Show(ShowHostedNetworkReason(WlanHnkReason), Text); break;
                }
                while (WlanHnkReason == 0 && !WlanMgr.IsHostedNetworkActive)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
                try { ICSRouter.StartSharing(InterfaceGuid, WlanMgr.HostedNetworkGuid); }
                catch (Exception ex)
                {
                    MessageBox.Show($"{ex.Message}", Text,
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

                break;

            case WLAN_HOSTED_NETWORK_STATE.wlan_hosted_network_idle:

                WlanHnkReason = WlanMgr.ForceStart();
                if (WlanHnkReason != 0)
                {
                    MessageBox.Show(ShowHostedNetworkReason(WlanHnkReason), Text); break;
                }
                while (WlanHnkReason == 0 && !WlanMgr.IsHostedNetworkActive)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
                try { ICSRouter.StartSharing(InterfaceGuid, WlanMgr.HostedNetworkGuid); }
                catch (Exception ex)
                {
                    MessageBox.Show($"{ex.Message}", Text,
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

                break;
            }
        }