From 6ed84641742fa558531374bb881af3cab2538465 Mon Sep 17 00:00:00 2001 From: loliprotector Date: Tue, 26 Nov 2019 14:35:13 +0800 Subject: [PATCH 1/2] Add option to skip host name scanning --- EvilLimiter.Windows/Forms/FrmScan.Designer.cs | 15 +++++++++++++++ EvilLimiter.Windows/Forms/FrmScan.cs | 4 ++-- EvilLimiter.Windows/Networking/HostScanner.cs | 9 ++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/EvilLimiter.Windows/Forms/FrmScan.Designer.cs b/EvilLimiter.Windows/Forms/FrmScan.Designer.cs index 1424346..1e9e6e5 100644 --- a/EvilLimiter.Windows/Forms/FrmScan.Designer.cs +++ b/EvilLimiter.Windows/Forms/FrmScan.Designer.cs @@ -39,6 +39,7 @@ private void InitializeComponent() this.pbScan = new MetroFramework.Controls.MetroProgressBar(); this.metroLabel1 = new MetroFramework.Controls.MetroLabel(); this.lblStatus = new MetroFramework.Controls.MetroLabel(); + this.scanHostNames = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // rbtnEntireRange @@ -176,12 +177,25 @@ private void InitializeComponent() this.lblStatus.Size = new System.Drawing.Size(0, 0); this.lblStatus.TabIndex = 6; // + // scanHostNames + // + this.scanHostNames.AutoSize = true; + this.scanHostNames.Checked = true; + this.scanHostNames.CheckState = System.Windows.Forms.CheckState.Checked; + this.scanHostNames.Location = new System.Drawing.Point(23, 224); + this.scanHostNames.Name = "scanHostNames"; + this.scanHostNames.Size = new System.Drawing.Size(105, 17); + this.scanHostNames.TabIndex = 7; + this.scanHostNames.Text = "Scan hostnames"; + this.scanHostNames.UseVisualStyleBackColor = true; + // // FrmScan // this.AcceptButton = this.btnScan; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(294, 308); + this.Controls.Add(this.scanHostNames); this.Controls.Add(this.lblStatus); this.Controls.Add(this.metroLabel1); this.Controls.Add(this.pbScan); @@ -218,5 +232,6 @@ private void InitializeComponent() private MetroFramework.Controls.MetroProgressBar pbScan; private MetroFramework.Controls.MetroLabel metroLabel1; private MetroFramework.Controls.MetroLabel lblStatus; + private System.Windows.Forms.CheckBox scanHostNames; } } \ No newline at end of file diff --git a/EvilLimiter.Windows/Forms/FrmScan.cs b/EvilLimiter.Windows/Forms/FrmScan.cs index e0055b0..70e3e6e 100644 --- a/EvilLimiter.Windows/Forms/FrmScan.cs +++ b/EvilLimiter.Windows/Forms/FrmScan.cs @@ -104,7 +104,7 @@ private void HostScanner_HostScanned(object sender, HostScannedEventArgs e) pbScan.Maximum = e.Total; pbScan.Value = e.Current; - if (e.Current == e.Total) + if (e.Current == e.Total && scanHostNames.Checked) { btnScan.Enabled = false; lblStatus.Text = "Resolving hostnames..."; @@ -144,7 +144,7 @@ private void BtnScan_Click(object sender, System.EventArgs e) range = _networkInfo.SubnetRange; ChangeScanState(ScanState.Scan); - _hostScanner.Scan(range); + _hostScanner.Scan(range, scanHostNames.Checked); } } diff --git a/EvilLimiter.Windows/Networking/HostScanner.cs b/EvilLimiter.Windows/Networking/HostScanner.cs index f828a7a..f70ebc3 100644 --- a/EvilLimiter.Windows/Networking/HostScanner.cs +++ b/EvilLimiter.Windows/Networking/HostScanner.cs @@ -52,7 +52,7 @@ public HostScanner(NetworkInformation netInfo) - public void Scan(ICollection addresses) + public void Scan(ICollection addresses, bool scanHosts = true) { if (IsScanning) return; @@ -137,8 +137,11 @@ public void Scan(ICollection addresses) Thread.Sleep(Config.ScanReplyTimeout); _tokenSource.Cancel(); - foreach (var host in discoveredHosts) - host.HostName = NetworkUtilities.GetHostNameByIp(host.IpAddress); + if(scanHosts) + { + foreach (var host in discoveredHosts) + host.HostName = NetworkUtilities.GetHostNameByIp(host.IpAddress); + } OnScanFinished(new ScanFinishedEventArgs(discoveredHosts)); } From abc4673c67f0a5a3de1486c3c252b8a5a8ea5452 Mon Sep 17 00:00:00 2001 From: bitbrute Date: Sat, 2 May 2020 20:43:01 +0200 Subject: [PATCH 2/2] Moving resolve hostnames option to settings page --- EvilLimiter.Windows/App.config | 3 ++- EvilLimiter.Windows/Common/Config.cs | 14 ++++++++++++++ EvilLimiter.Windows/Forms/FrmMain.Designer.cs | 19 +++++++++++++++++-- EvilLimiter.Windows/Forms/FrmMain.cs | 2 ++ EvilLimiter.Windows/Forms/FrmScan.Designer.cs | 15 --------------- EvilLimiter.Windows/Forms/FrmScan.cs | 7 ++++--- EvilLimiter.Windows/Networking/HostScanner.cs | 4 ++-- 7 files changed, 41 insertions(+), 23 deletions(-) diff --git a/EvilLimiter.Windows/App.config b/EvilLimiter.Windows/App.config index 9e34643..cdc3a42 100644 --- a/EvilLimiter.Windows/App.config +++ b/EvilLimiter.Windows/App.config @@ -4,10 +4,11 @@ - + + diff --git a/EvilLimiter.Windows/Common/Config.cs b/EvilLimiter.Windows/Common/Config.cs index cf0c490..72d5b51 100644 --- a/EvilLimiter.Windows/Common/Config.cs +++ b/EvilLimiter.Windows/Common/Config.cs @@ -32,6 +32,12 @@ public static int ScanReplyTimeout set { lock (_scanReplyTimeoutLock) _scanReplyTimeout = value; } } + public static bool ScanResolveHostnames + { + get { lock (_scanResolveHostnamesLock) return _scanResolveHostnames; } + set { lock (_scanResolveHostnamesLock) _scanResolveHostnames = value; } + } + public static int SpoofSendInterval { @@ -69,6 +75,8 @@ public static int BandwidthMonitorUpdateInterval private static readonly object _scanSendIntervalLock; private static int _scanReplyTimeout; private static readonly object _scanReplyTimeoutLock; + private static bool _scanResolveHostnames; + private static readonly object _scanResolveHostnamesLock; private static int _spoofSendInterval; private static readonly object _spoofSendIntervalLock; @@ -88,6 +96,7 @@ static Config() _colorStyle = MetroColorStyle.Default; _scanSendInterval = 10; _scanReplyTimeout = 2000; + _scanResolveHostnames = true; _spoofSendInterval = 4000; _spoofRestoreSendCount = 3; _spoofRestoreSendInterval = 50; @@ -97,10 +106,13 @@ static Config() _colorStyleLock = new object(); _scanSendIntervalLock = new object(); _scanReplyTimeoutLock = new object(); + _scanResolveHostnamesLock = new object(); _spoofSendIntervalLock = new object(); _spoofRestoreSendCountLock = new object(); _spoofRestoreSendIntervalLock = new object(); _bandwidthMonitorUpdateIntervalLock = new object(); + + System.Console.WriteLine(true.ToString()); } @@ -117,6 +129,7 @@ public static bool Read() ScanSendInterval = int.Parse(config.AppSettings.Settings["ScanSendInterval"].Value); ScanReplyTimeout = int.Parse(config.AppSettings.Settings["ScanReplyTimeout"].Value); + ScanResolveHostnames = bool.Parse(config.AppSettings.Settings["ScanResolveHostnames"].Value); SpoofSendInterval = int.Parse(config.AppSettings.Settings["SpoofSendInterval"].Value); SpoofRestoreSendCount = int.Parse(config.AppSettings.Settings["SpoofRestoreSendCount"].Value); @@ -145,6 +158,7 @@ public static bool Write() config.AppSettings.Settings["ScanSendInterval"].Value = ScanSendInterval.ToString(); config.AppSettings.Settings["ScanReplyTimeout"].Value = ScanReplyTimeout.ToString(); + config.AppSettings.Settings["ScanResolveHostnames"].Value = ScanResolveHostnames.ToString(); config.AppSettings.Settings["SpoofSendInterval"].Value = SpoofSendInterval.ToString(); config.AppSettings.Settings["SpoofRestoreSendCount"].Value = SpoofRestoreSendCount.ToString(); diff --git a/EvilLimiter.Windows/Forms/FrmMain.Designer.cs b/EvilLimiter.Windows/Forms/FrmMain.Designer.cs index 721eaf9..b10ae1b 100644 --- a/EvilLimiter.Windows/Forms/FrmMain.Designer.cs +++ b/EvilLimiter.Windows/Forms/FrmMain.Designer.cs @@ -87,6 +87,7 @@ private void InitializeComponent() this.lnkEvilLimiter = new MetroFramework.Controls.MetroLink(); this.metroLabel15 = new MetroFramework.Controls.MetroLabel(); this.metroLabel14 = new MetroFramework.Controls.MetroLabel(); + this.cbScanResolveHostnames = new MetroFramework.Controls.MetroCheckBox(); this.cmsHosts.SuspendLayout(); this.tcHosts.SuspendLayout(); this.tpHosts.SuspendLayout(); @@ -251,7 +252,7 @@ private void InitializeComponent() this.tcHosts.Controls.Add(this.tpAbout); this.tcHosts.Location = new System.Drawing.Point(23, 79); this.tcHosts.Name = "tcHosts"; - this.tcHosts.SelectedIndex = 0; + this.tcHosts.SelectedIndex = 1; this.tcHosts.Size = new System.Drawing.Size(718, 376); this.tcHosts.TabIndex = 4; this.tcHosts.UseSelectable = true; @@ -313,7 +314,7 @@ private void InitializeComponent() this.tcSettings.FontSize = MetroFramework.MetroTabControlSize.Small; this.tcSettings.Location = new System.Drawing.Point(0, 13); this.tcSettings.Name = "tcSettings"; - this.tcSettings.SelectedIndex = 4; + this.tcSettings.SelectedIndex = 1; this.tcSettings.Size = new System.Drawing.Size(710, 289); this.tcSettings.TabIndex = 2; this.tcSettings.UseSelectable = true; @@ -380,6 +381,7 @@ private void InitializeComponent() // // tpScanSettings // + this.tpScanSettings.Controls.Add(this.cbScanResolveHostnames); this.tpScanSettings.Controls.Add(this.metroLabel6); this.tpScanSettings.Controls.Add(this.metroLabel5); this.tpScanSettings.Controls.Add(this.tbScanReplyTimeout); @@ -839,6 +841,18 @@ private void InitializeComponent() this.metroLabel14.TabIndex = 2; this.metroLabel14.Text = "This is the Windows version of the linux command-line tool ."; // + // cbScanResolveHostnames + // + this.cbScanResolveHostnames.AutoSize = true; + this.cbScanResolveHostnames.Checked = true; + this.cbScanResolveHostnames.CheckState = System.Windows.Forms.CheckState.Checked; + this.cbScanResolveHostnames.Location = new System.Drawing.Point(4, 145); + this.cbScanResolveHostnames.Name = "cbScanResolveHostnames"; + this.cbScanResolveHostnames.Size = new System.Drawing.Size(126, 15); + this.cbScanResolveHostnames.TabIndex = 9; + this.cbScanResolveHostnames.Text = "Resolve Hostnames"; + this.cbScanResolveHostnames.UseSelectable = true; + // // FrmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -931,5 +945,6 @@ private void InitializeComponent() private MetroFramework.Controls.MetroLink lnkGitHubPage; private MetroFramework.Controls.MetroLabel metroLabel15; private MetroFramework.Controls.MetroLabel metroLabel17; + private MetroFramework.Controls.MetroCheckBox cbScanResolveHostnames; } } \ No newline at end of file diff --git a/EvilLimiter.Windows/Forms/FrmMain.cs b/EvilLimiter.Windows/Forms/FrmMain.cs index 4b8a302..123d34a 100644 --- a/EvilLimiter.Windows/Forms/FrmMain.cs +++ b/EvilLimiter.Windows/Forms/FrmMain.cs @@ -77,6 +77,7 @@ private void UpdateConfigDisplay() tbScanSendInterval.Text = Config.ScanSendInterval.ToString(); tbScanReplyTimeout.Text = Config.ScanReplyTimeout.ToString(); + cbScanResolveHostnames.Checked = Config.ScanResolveHostnames; tbSpoofSendInterval.Text = Config.SpoofSendInterval.ToString(); tbSpoofRestoreSendCount.Text = Config.SpoofRestoreSendCount.ToString(); tbSpoofRestoreSendInterval.Text = Config.SpoofRestoreSendInterval.ToString(); @@ -362,6 +363,7 @@ private void BtnApplySettings_Click(object sender, EventArgs e) Config.ColorStyle = colorStyle; Config.ScanSendInterval = scanSendInterval; Config.ScanReplyTimeout = scanReplyTimeout; + Config.ScanResolveHostnames = cbScanResolveHostnames.Checked; Config.SpoofSendInterval = spoofSendInterval; Config.SpoofRestoreSendCount = spoofRestoreSendCount; Config.SpoofRestoreSendInterval = spoofRestoreSendInterval; diff --git a/EvilLimiter.Windows/Forms/FrmScan.Designer.cs b/EvilLimiter.Windows/Forms/FrmScan.Designer.cs index 1e9e6e5..1424346 100644 --- a/EvilLimiter.Windows/Forms/FrmScan.Designer.cs +++ b/EvilLimiter.Windows/Forms/FrmScan.Designer.cs @@ -39,7 +39,6 @@ private void InitializeComponent() this.pbScan = new MetroFramework.Controls.MetroProgressBar(); this.metroLabel1 = new MetroFramework.Controls.MetroLabel(); this.lblStatus = new MetroFramework.Controls.MetroLabel(); - this.scanHostNames = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // rbtnEntireRange @@ -177,25 +176,12 @@ private void InitializeComponent() this.lblStatus.Size = new System.Drawing.Size(0, 0); this.lblStatus.TabIndex = 6; // - // scanHostNames - // - this.scanHostNames.AutoSize = true; - this.scanHostNames.Checked = true; - this.scanHostNames.CheckState = System.Windows.Forms.CheckState.Checked; - this.scanHostNames.Location = new System.Drawing.Point(23, 224); - this.scanHostNames.Name = "scanHostNames"; - this.scanHostNames.Size = new System.Drawing.Size(105, 17); - this.scanHostNames.TabIndex = 7; - this.scanHostNames.Text = "Scan hostnames"; - this.scanHostNames.UseVisualStyleBackColor = true; - // // FrmScan // this.AcceptButton = this.btnScan; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(294, 308); - this.Controls.Add(this.scanHostNames); this.Controls.Add(this.lblStatus); this.Controls.Add(this.metroLabel1); this.Controls.Add(this.pbScan); @@ -232,6 +218,5 @@ private void InitializeComponent() private MetroFramework.Controls.MetroProgressBar pbScan; private MetroFramework.Controls.MetroLabel metroLabel1; private MetroFramework.Controls.MetroLabel lblStatus; - private System.Windows.Forms.CheckBox scanHostNames; } } \ No newline at end of file diff --git a/EvilLimiter.Windows/Forms/FrmScan.cs b/EvilLimiter.Windows/Forms/FrmScan.cs index 70e3e6e..c884f22 100644 --- a/EvilLimiter.Windows/Forms/FrmScan.cs +++ b/EvilLimiter.Windows/Forms/FrmScan.cs @@ -1,4 +1,5 @@ -using EvilLimiter.Windows.Data; +using EvilLimiter.Windows.Common; +using EvilLimiter.Windows.Data; using EvilLimiter.Windows.Networking; using EvilLimiter.Windows.Utilities; using MetroFramework; @@ -104,7 +105,7 @@ private void HostScanner_HostScanned(object sender, HostScannedEventArgs e) pbScan.Maximum = e.Total; pbScan.Value = e.Current; - if (e.Current == e.Total && scanHostNames.Checked) + if (e.Current == e.Total && Config.ScanResolveHostnames) { btnScan.Enabled = false; lblStatus.Text = "Resolving hostnames..."; @@ -144,7 +145,7 @@ private void BtnScan_Click(object sender, System.EventArgs e) range = _networkInfo.SubnetRange; ChangeScanState(ScanState.Scan); - _hostScanner.Scan(range, scanHostNames.Checked); + _hostScanner.Scan(range, Config.ScanResolveHostnames); } } diff --git a/EvilLimiter.Windows/Networking/HostScanner.cs b/EvilLimiter.Windows/Networking/HostScanner.cs index f70ebc3..e37cdcf 100644 --- a/EvilLimiter.Windows/Networking/HostScanner.cs +++ b/EvilLimiter.Windows/Networking/HostScanner.cs @@ -52,7 +52,7 @@ public HostScanner(NetworkInformation netInfo) - public void Scan(ICollection addresses, bool scanHosts = true) + public void Scan(ICollection addresses, bool resolveHostnames = true) { if (IsScanning) return; @@ -137,7 +137,7 @@ public void Scan(ICollection addresses, bool scanHosts = true) Thread.Sleep(Config.ScanReplyTimeout); _tokenSource.Cancel(); - if(scanHosts) + if(resolveHostnames) { foreach (var host in discoveredHosts) host.HostName = NetworkUtilities.GetHostNameByIp(host.IpAddress);