public List <Host> HostDiscover(bool known, string ip = "192.168.137.0", string range = "24") { Target target; var foundHosts = new List <Host>(); Console.WriteLine(""); if (known) { target = new Target(ip); Console.WriteLine($"Host discovery started on {ip}, please wait..."); foundHosts.AddRange(new Scanner(target).HostDiscovery()); } else { var localIpRanges = NetworkInterfaceHelper.ConvertLocalIpToRange(LocalIPList); Console.WriteLine("Host discovery scan started, please wait..."); foreach (var address in localIpRanges.Where(x => !x.Contains("100.74.172.0"))) //exclude my apartment building { target = new Target($"{address}/{range}"); var discovery = new Scanner(target).HostDiscovery(); foundHosts.AddRange(discovery); Console.WriteLine($"Host discovery found {discovery.Count()} online devices in {address}/{range}"); } } Console.WriteLine($"Host discovery scan completed, {foundHosts.Count} online devices have been found."); return(foundHosts); }
public ForwardingDnsServer( IOptions <VtunerConfig> cfg, ILogger <ForwardingDnsServer> logger, NetworkInterfaceHelper networkInterfaceHelper) { this._cfg = cfg.Value; this._logger = logger; this._networkInterfaceHelper = networkInterfaceHelper; }
private void FrmMain_Load(object sender, EventArgs e) { try { Util.TranslateUtil.InitLanguage(); txtConsole.Text = NetworkInterfaceHelper.GetActiveConnection(); ReloadLanguage(); } catch (Exception e1) { MessageBox.Show(this, e1.Message); } }
private void tsbApply_Click(object sender, EventArgs e) { if (TabProfiles.SelectedTab == tabProfile) { try { if (lstProfiles.SelectedValue != null) { bool error = false; if (!profileSelected.DhcpEnabled) { if (!(NetworkInterfaceHelper.SetIP(profileSelected.MacAddress, profileSelected.IpAddress, profileSelected.IpSubnet, profileSelected.DefaultIpGateway))) { MessageBox.Show(this, TranslateUtil.GetMsgErrorNetworkInterface(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); error = true; } } else { new Thread(StartDHCPRenew).Start(); } if (!profileSelected.DnsServerSearchOrder.Trim().Equals(String.Empty)) { if (!(NetworkInterfaceHelper.SetDNS(profileSelected.MacAddress, profileSelected.DnsServerSearchOrder))) { MessageBox.Show(this, TranslateUtil.GetMsgErrorDNSNetworkInterface(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); error = true; } } else { NetworkInterfaceHelper.SetDNSAutomatically(profileSelected.MacAddress); } if (!error && !profileSelected.DhcpEnabled) { MessageBox.Show(this, String.Format(TranslateUtil.GetMsgAppliedProfile(), ((Profile)lstProfiles.SelectedItem).ProfileName), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtConsole.Text = NetworkInterfaceHelper.GetActiveConnection(); } } else { MessageBox.Show(this, TranslateUtil.GetMsgSelectProfile(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show(this, TranslateUtil.GetMsgErrorSetting(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { List <IPAddress> localIPs = NetworkInterfaceHelper.GetHostIPAddresses(); KeyValuePairList <string, IPAddress> list = new KeyValuePairList <string, IPAddress>(); list.Add("Any", IPAddress.Any); foreach (IPAddress address in localIPs) { if (address.ToString().Equals("127.0.0.1")) { continue; } list.Add(address.ToString(), address); } this.address_combobox.ItemsSource = list; this.address_combobox.DisplayMemberPath = "Key"; this.address_combobox.SelectedIndex = 0; UserCollection users = this.GetUserCollection(); if (users != null) { List <string> userNames = users.ListUsers(); if (userNames.Count > 0) { string username = userNames[0]; this.username_textbox.Text = username; this.password_box.Password = users.GetUserPassword(username); } } m_sharesSettings = this.GetShareSettings(); this.shares_listbox.ItemsSource = m_sharesSettings; this.shares_listbox.DisplayMemberPath = "SharePath"; int port = SettingsHelper.ReadServerPort(); this.port_textbox.Text = port.ToString(); bool shouldRunAsService = SettingsHelper.ReadRunAsService(); this.service_checkbox.IsChecked = shouldRunAsService; }
private void tsbSave_Click(object sender, EventArgs e) { try { if (TabProfiles.SelectedIndex == 1) { Profile p = new Profile(); ProfileHelper pHelper = new ProfileHelper(); NetworkInterface ni = NetworkInterfaceHelper.GetByMACNetworkInterface(cmbInterfaces.SelectedValue.ToString()); p.Caption = ni.Caption; p.Description = ni.Description; p.ProfileName = txtProfile.Text; p.ServiceName = ni.ServiceName; p.SettingId = ni.SettingID; p.DhcpEnabled = this.rdbIpAutomatically.Checked; p.MacAddress = ni.MACAddress; if (!p.DhcpEnabled) { p.DefaultIpGateway = txtGateway.Text; p.IpSubnet = txtIPSubnet.Text; p.IpAddress = txtIPAddress.Text; } if (!rdbDNSAutomatically.Checked) { p.DnsServerSearchOrder = txtDNSServer.Text; } pHelper.Add(p); LoadProfiles(); LoadNew(); MessageBox.Show(this, TranslateUtil.GetMsgSavedProfile(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch { MessageBox.Show(this, TranslateUtil.GetMsgErrorProfile(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void RunOptions(Options opts) { logger.Info("Options: {0}", opts); List <ShareSettings> sharesSettings; try { sharesSettings = SettingsHelper.ReadSharesSettings(); } catch (Exception) { logger.Error("Cannot read " + SettingsHelper.SettingsFileName); return; } List <AggregatedShareSettings> aggregatedSharesSettings; try { aggregatedSharesSettings = SettingsHelper.ReadAggregatedSharesSettings(); } catch (Exception) { logger.Error("Cannot read " + SettingsHelper.SettingsFileName); return; } SMBShareCollection shares = new SMBShareCollection(); foreach (ShareSettings shareSettings in sharesSettings) { FileSystemShare share = InitializeShare(shareSettings); shares.Add(share); } foreach (AggregatedShareSettings settings in aggregatedSharesSettings) { FileSystemShare share = InitializeAggFSShare(settings); shares.Add(share); } NTLMAuthenticationProviderBase authenticationMechanism = new IntegratedNTLMAuthenticationProvider(); GSSProvider securityProvider = new GSSProvider(authenticationMechanism); theServer = new SMBLibrary.Server.SMBServer(shares, securityProvider); if (opts.Verbose) { theServer.LogEntryAdded += TheServer_LogEntryAdded; } bool enableSMB1 = (opts.SMBProtocol & SMBProtocol.SMB1) == SMBProtocol.SMB1; bool enableSMB2 = (opts.SMBProtocol & SMBProtocol.SMB2) == SMBProtocol.SMB2; bool enableSMB3 = (opts.SMBProtocol & SMBProtocol.SMB3) == SMBProtocol.SMB3; IPAddress listenAddr; if (!IPAddress.TryParse(opts.ListenIPAddress, out listenAddr)) { logger.Error(opts.ListenIPAddress + " is not a valid IP Address."); Environment.Exit(-1); return; } try { theServer.Start(listenAddr, opts.TransportType, enableSMB1, enableSMB2, enableSMB3); if (opts.TransportType == SMBTransportType.NetBiosOverTCP) { if (listenAddr.AddressFamily == AddressFamily.InterNetwork && !IPAddress.Equals(listenAddr, IPAddress.Any)) { IPAddress subnetMask = NetworkInterfaceHelper.GetSubnetMask(listenAddr); theNameServer = new NameServer(listenAddr, subnetMask); theNameServer.Start(); } } Console.Read(); } catch (Exception ex) { logger.Error(ex.Message); Environment.Exit(-1); return; } }
public override ILoadBalancer CreateResource(ILoadBalancers resources) { pips = resources.Manager.PublicIPAddresses; networks = resources.Manager.Networks; availabilitySets = computeManager.AvailabilitySets; var existingVMs = loadBalancerHelper.EnsureVMs(networks, computeManager, 2); Assert.Equal(2, existingVMs.Count()); var existingPips = loadBalancerHelper.EnsurePIPs(pips); var nic1 = existingVMs.ElementAt(0).GetPrimaryNetworkInterface(); var nic2 = existingVMs.ElementAt(1).GetPrimaryNetworkInterface(); IPublicIPAddress pip = resources.Manager.PublicIPAddresses.GetByResourceGroup( loadBalancerHelper.GroupName, loadBalancerHelper.PipNames[0]); // Create a load balancer var lb = resources.Define(loadBalancerHelper.LoadBalancerName) .WithRegion(loadBalancerHelper.Region) .WithExistingResourceGroup(loadBalancerHelper.GroupName) // Load balancing rules .DefineLoadBalancingRule("rule1") .WithProtocol(TransportProtocol.Tcp) // Required .FromExistingPublicIPAddress(pip) .FromFrontendPort(81) .ToBackend("backend1") .ToBackendPort(82) // Optionals .WithProbe("tcpProbe1") .WithIdleTimeoutInMinutes(10) .WithLoadDistribution(LoadDistribution.SourceIP) .Attach() // Inbound NAT rules .DefineInboundNatRule("natrule1") .WithProtocol(TransportProtocol.Tcp) .FromExistingPublicIPAddress(pip) // Implicitly uses the same frontend because the PIP is the same .FromFrontendPort(88) .Attach() // Probes .DefineTcpProbe("tcpProbe1") .WithPort(25) // Required .WithIntervalInSeconds(15) // Optionals .WithNumberOfProbes(5) .Attach() .DefineHttpProbe("httpProbe1") .WithRequestPath("/") // Required .WithIntervalInSeconds(13) // Optionals .WithNumberOfProbes(4) .Attach() .Create(); string backendName = lb.Backends.Values.First().Name; string frontendName = lb.Frontends.Values.First().Name; // Connect NICs explicitly nic1.Update() .WithExistingLoadBalancerBackend(lb, backendName) .WithExistingLoadBalancerInboundNatRule(lb, "natrule1") .Apply(); NetworkInterfaceHelper.PrintNic(nic1); Assert.Equal(nic1.PrimaryIPConfiguration.ListAssociatedLoadBalancerBackends().ElementAt(0) .Name, backendName, ignoreCase: true); Assert.Equal("natrule1", nic1.PrimaryIPConfiguration.ListAssociatedLoadBalancerInboundNatRules().ElementAt(0) .Name, ignoreCase: true); nic2.Update() .WithExistingLoadBalancerBackend(lb, backendName) .Apply(); NetworkInterfaceHelper.PrintNic(nic2); Assert.Equal(nic2.PrimaryIPConfiguration.ListAssociatedLoadBalancerBackends().ElementAt(0) .Name, backendName, ignoreCase: true); // Verify frontends Assert.Single(lb.Frontends.Values); Assert.Single(lb.PublicFrontends.Values); Assert.Empty(lb.PrivateFrontends.Values); Assert.True(lb.Frontends.ContainsKey(frontendName)); var frontend = lb.Frontends[frontendName]; Assert.True(frontend.IsPublic); var publicFrontend = (ILoadBalancerPublicFrontend)frontend; Assert.Equal(pip.Id, publicFrontend.PublicIPAddressId, ignoreCase: true); pip.Refresh(); Assert.Equal(pip.GetAssignedLoadBalancerFrontend().Name, frontendName, ignoreCase: true); // Verify backends Assert.True(lb.Backends.ContainsKey(backendName)); Assert.Single(lb.Backends.Values); // Verify probes Assert.True(lb.HttpProbes.ContainsKey("httpProbe1")); Assert.Single(lb.HttpProbes.Values); Assert.True(lb.TcpProbes.ContainsKey("tcpProbe1")); Assert.Single(lb.TcpProbes.Values); // Verify rules Assert.Single(lb.LoadBalancingRules.Values); Assert.True(lb.LoadBalancingRules.ContainsKey("rule1")); var rule = lb.LoadBalancingRules["rule1"]; Assert.Equal(rule.Backend.Name, backendName, ignoreCase: true); Assert.Equal(rule.Frontend.Name, frontendName, ignoreCase: true); Assert.Equal("tcpProbe1", rule.Probe.Name, ignoreCase: true); // Verify inbound NAT rules Assert.Single(lb.InboundNatRules.Values); Assert.True(lb.InboundNatRules.ContainsKey("natrule1")); var inboundNatRule = lb.InboundNatRules["natrule1"]; Assert.Equal(inboundNatRule.Frontend.Name, frontendName, ignoreCase: true); Assert.Equal(88, inboundNatRule.FrontendPort); Assert.Equal(88, inboundNatRule.BackendPort); return(lb); }
private void StartButton_Click(object sender, RoutedEventArgs e) { string accountName = this.username_textbox.Text; string password = this.password_box.Password; if (CommonUtils.IsEmptyString(accountName)) { MessageBox.Show("User Name or Password cannot be empty!", "Error"); return; } List <ShareSettings> sharesSettings = this.GetShareSettings(); if (sharesSettings == null || sharesSettings.Count == 0) { MessageBox.Show("Please add directories for sharing!", "Error"); return; } int port = SettingsHelper.DefaultPort; try { port = int.Parse(this.port_textbox.Text); SettingsHelper.WriteServerPort(port); } catch { MessageBox.Show("Invalid port number!", "Error"); return; } UserCollection users = new UserCollection(); users.Add(new User(accountName, password)); // Save account if necessary if (this.NeedUpdateUserCollection()) { SettingsHelper.WriteUserSettings(users); } bool runAsService = this.service_checkbox.IsChecked ?? false; if (runAsService) { if (!this.IsInAdminRole()) { MessageBox.Show("To start the service, please run application as administrator.", "Info"); return; } try { ServiceController serviceController = new ServiceController("RedfishService"); serviceController.Start(); this.start_button.IsEnabled = false; this.stop_button.IsEnabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } else { KeyValuePair <string, IPAddress> selectedValue = (KeyValuePair <string, IPAddress>) this.address_combobox.SelectedValue; IPAddress serverAddress = selectedValue.Value; SMBTransportType transportType = SMBTransportType.DirectTCPTransport; NTLMAuthenticationProviderBase authenticationMechanism = new IndependentNTLMAuthenticationProvider(users.GetUserPassword); SMBShareCollection shares = new SMBShareCollection(); foreach (ShareSettings shareSettings in sharesSettings) { FileSystemShare share = shareSettings.InitializeShare(); shares.Add(share); } GSSProvider securityProvider = new GSSProvider(authenticationMechanism); m_server = new SMBLibrary.Server.SMBServer(shares, securityProvider); m_logWriter = new LogWriter(); // The provided logging mechanism will synchronously write to the disk during server activity. // To maximize server performance, you can disable logging by commenting out the following line. m_server.LogEntryAdded += new EventHandler <LogEntry>(m_logWriter.OnLogEntryAdded); try { SMBServer.DirectTCPPort = port; m_server.Start(serverAddress, transportType); if (transportType == SMBTransportType.NetBiosOverTCP) { if (serverAddress.AddressFamily == AddressFamily.InterNetwork && !IPAddress.Equals(serverAddress, IPAddress.Any)) { IPAddress subnetMask = NetworkInterfaceHelper.GetSubnetMask(serverAddress); m_nameServer = new NameServer(serverAddress, subnetMask); m_nameServer.Start(); } } this.start_button.IsEnabled = false; this.stop_button.IsEnabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } }
private void StartDHCPRenew() { NetworkInterfaceHelper.SetEnabledDHCP(profileSelected.MacAddress); MessageBox.Show(this, String.Format(TranslateUtil.GetMsgAppliedProfile(), ((Profile)lstProfiles.SelectedItem).ProfileName), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtConsole.Text = NetworkInterfaceHelper.GetActiveConnection(); }