private string FindHostedNetworkId() { foreach (var nic in IcsManager.GetAllIPv4Interfaces()) { if (nic.OperationalStatus == OperationalStatus.Up && HasHostedNetworkAttrs(nic)) { return(nic.Id); } } return(null); }
private bool PopulateNetworkList(string SelStr = null) { try { cbSourceNetworks.BeginUpdate(); cbSourceNetworks.Items.Clear(); int idx = -1; foreach (var nic in IcsManager.GetAllIPv4Interfaces()) { if (nic.OperationalStatus != OperationalStatus.Up || HasHostedNetworkAttrs(nic)) { continue; } string name = nic.Name; if (!string.IsNullOrEmpty(SelStr) && name.Equals(SelStr, StringComparison.CurrentCulture)) { idx = cbSourceNetworks.Items.Count; SelStr = null; } cbSourceNetworks.Items.Add(new NicItem( Name: name, Guid: nic.Id, Description: nic.Description )); } cbSourceNetworks.EndUpdate(); if (idx == -1) { idx = 0; } if (cbSourceNetworks.Items.Count > 0) { cbSourceNetworks.SelectedIndex = idx; } return(true); } catch (Exception) { return(false); } }
static void DisableInternetSharing() { try { var currentShare = IcsManager.GetCurrentlySharedConnections(); if (!currentShare.Exists) { return; } IcsManager.ShareConnection(null, null); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
static bool EnableInternetSharing( string SrcNetName, string HostedNetName, bool bForce) { string err = null; try { do { var SrcNet = IcsManager.FindConnectionByIdOrName(SrcNetName); if (SrcNet == null) { err = "Connection not found: " + SrcNetName; break; } var HostedNet = IcsManager.FindConnectionByIdOrName(HostedNetName); if (HostedNet == null) { err = "Could not find network " + HostedNetName; break; } IcsManager.ShareConnection( SrcNet, HostedNet); } while (false); } catch (Exception ex) { err = ex.Message; } if (!string.IsNullOrEmpty(err)) { MessageBox.Show(err, "Error"); return(false); } return(true); }