Add FrmIPScan

This commit is contained in:
2017-12-24 14:54:01 +01:00
parent 39c13c394b
commit d4eac4095c
5 changed files with 231 additions and 4 deletions

101
VAR.Toolbox/UI/FrmIPScan.Designer.cs generated Normal file
View File

@@ -0,0 +1,101 @@
namespace VAR.Toolbox.UI
{
partial class FrmIPScan
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lsvResult = new System.Windows.Forms.ListBox();
this.btnScan = new System.Windows.Forms.Button();
this.lblStatus = new System.Windows.Forms.Label();
this.btnStop = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lsvResult
//
this.lsvResult.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lsvResult.FormattingEnabled = true;
this.lsvResult.ItemHeight = 20;
this.lsvResult.Location = new System.Drawing.Point(13, 62);
this.lsvResult.Name = "lsvResult";
this.lsvResult.Size = new System.Drawing.Size(523, 404);
this.lsvResult.TabIndex = 0;
//
// btnScan
//
this.btnScan.Location = new System.Drawing.Point(13, 12);
this.btnScan.Name = "btnScan";
this.btnScan.Size = new System.Drawing.Size(91, 33);
this.btnScan.TabIndex = 1;
this.btnScan.Text = "Scan";
this.btnScan.UseVisualStyleBackColor = true;
this.btnScan.Click += new System.EventHandler(this.btnScan_Click);
//
// lblStatus
//
this.lblStatus.AutoSize = true;
this.lblStatus.Location = new System.Drawing.Point(248, 18);
this.lblStatus.Name = "lblStatus";
this.lblStatus.Size = new System.Drawing.Size(71, 20);
this.lblStatus.TabIndex = 2;
this.lblStatus.Text = "lblStatus";
//
// btnStop
//
this.btnStop.Location = new System.Drawing.Point(110, 12);
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(91, 33);
this.btnStop.TabIndex = 3;
this.btnStop.Text = "Stop";
this.btnStop.UseVisualStyleBackColor = true;
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// FrmIPScan
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(548, 473);
this.Controls.Add(this.btnStop);
this.Controls.Add(this.lblStatus);
this.Controls.Add(this.btnScan);
this.Controls.Add(this.lsvResult);
this.Name = "FrmIPScan";
this.Text = "IPScan";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ListBox lsvResult;
private System.Windows.Forms.Button btnScan;
private System.Windows.Forms.Label lblStatus;
private System.Windows.Forms.Button btnStop;
}
}

102
VAR.Toolbox/UI/FrmIPScan.cs Normal file
View File

@@ -0,0 +1,102 @@
using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
namespace VAR.Toolbox.UI
{
public partial class FrmIPScan : Form
{
public FrmIPScan()
{
InitializeComponent();
PrintStatus("Idle");
}
private void PrintStatus(string status)
{
if (lblStatus.InvokeRequired)
{
lblStatus.Invoke((MethodInvoker)(() => { lblStatus.Text = string.Format("Status: {0}", status); }));
}
else
{
lblStatus.Text = string.Format("Status: {0}", status);
Application.DoEvents();
}
}
private void ResultsAddLine(string line)
{
if (lsvResult.InvokeRequired)
{
lsvResult.Invoke((MethodInvoker)(() => { lsvResult.Items.Add(line); }));
}
else
{
lsvResult.Items.Add(line);
Application.DoEvents();
}
}
private void Control_SetEnabled(Control ctrl, bool enabled)
{
if (ctrl.InvokeRequired)
{
ctrl.Invoke((MethodInvoker)(() => { ctrl.Enabled = enabled; }));
}
else
{
ctrl.Enabled = enabled;
Application.DoEvents();
}
}
private void btnScan_Click(object sender, EventArgs e)
{
Thread thread = new Thread(() => { IPScan(); });
thread.Start();
}
private void btnStop_Click(object sender, EventArgs e)
{
running = false;
}
private bool running = false;
private void IPScan()
{
Control_SetEnabled(btnScan, false);
running = true;
ResultsAddLine(string.Format("IPScan started at {0}", DateTime.UtcNow.ToString("s")));
string ipBase = "192.168.0.";
for (int i = 1; i < 255 && running; i++)
{
string ip = ipBase + i.ToString();
PrintStatus(string.Format("Scanning {0}", ip));
Ping p = new Ping();
PingReply pingReply = p.Send(ip, 100);
if (pingReply.Status == IPStatus.Success)
{
string name = "?";
try
{
IPHostEntry hostEntry = Dns.GetHostEntry(ip);
name = hostEntry.HostName;
}
catch (SocketException) { }
ResultsAddLine(string.Format("{0} ({1}) is up: ({2} ms)", ip, name, pingReply.RoundtripTime));
}
Application.DoEvents();
}
PrintStatus("Idle");
ResultsAddLine(string.Format("IPScan ended at {0}", DateTime.UtcNow.ToString("s")));
Control_SetEnabled(btnScan, true);
}
}
}

View File

@@ -41,6 +41,7 @@
this.btnTestSoapService = new System.Windows.Forms.Button();
this.btnTestRestService = new System.Windows.Forms.Button();
this.btnScreenshooter = new System.Windows.Forms.Button();
this.btnIPScan = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnBase64
@@ -78,7 +79,7 @@
//
// btnTunnelTCP
//
this.btnTunnelTCP.Location = new System.Drawing.Point(14, 269);
this.btnTunnelTCP.Location = new System.Drawing.Point(12, 271);
this.btnTunnelTCP.Name = "btnTunnelTCP";
this.btnTunnelTCP.Size = new System.Drawing.Size(248, 55);
this.btnTunnelTCP.TabIndex = 5;
@@ -101,7 +102,7 @@
// pnlSuspension1
//
this.pnlSuspension1.Location = new System.Drawing.Point(270, 371);
this.pnlSuspension1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.pnlSuspension1.Margin = new System.Windows.Forms.Padding(2);
this.pnlSuspension1.Name = "pnlSuspension1";
this.pnlSuspension1.Size = new System.Drawing.Size(248, 175);
this.pnlSuspension1.TabIndex = 4;
@@ -109,7 +110,7 @@
// pnlCover1
//
this.pnlCover1.Location = new System.Drawing.Point(18, 371);
this.pnlCover1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.pnlCover1.Margin = new System.Windows.Forms.Padding(2);
this.pnlCover1.Name = "pnlCover1";
this.pnlCover1.Size = new System.Drawing.Size(243, 175);
this.pnlCover1.TabIndex = 3;
@@ -164,11 +165,23 @@
this.btnScreenshooter.UseVisualStyleBackColor = true;
this.btnScreenshooter.Click += new System.EventHandler(this.btnScreenshooter_Click);
//
// btnIPScan
//
this.btnIPScan.Location = new System.Drawing.Point(270, 271);
this.btnIPScan.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.btnIPScan.Name = "btnIPScan";
this.btnIPScan.Size = new System.Drawing.Size(248, 55);
this.btnIPScan.TabIndex = 11;
this.btnIPScan.Text = "IPScan";
this.btnIPScan.UseVisualStyleBackColor = true;
this.btnIPScan.Click += new System.EventHandler(this.btnIPScan_Click);
//
// FrmToolbox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(528, 615);
this.Controls.Add(this.btnIPScan);
this.Controls.Add(this.btnScreenshooter);
this.Controls.Add(this.btnTestRestService);
this.Controls.Add(this.btnTestSoapService);
@@ -206,6 +219,7 @@
private System.Windows.Forms.Button btnTestSoapService;
private System.Windows.Forms.Button btnTestRestService;
private System.Windows.Forms.Button btnScreenshooter;
private System.Windows.Forms.Button btnIPScan;
}
}

View File

@@ -110,6 +110,11 @@ namespace VAR.Toolbox.UI
CreateWindow(typeof(FrmScreenshooter));
}
private void btnIPScan_Click(object sender, EventArgs e)
{
CreateWindow(typeof(FrmIPScan));
}
#endregion UI events
#region Window handling
@@ -184,6 +189,5 @@ namespace VAR.Toolbox.UI
}
#endregion Window handling
}
}

View File

@@ -102,6 +102,12 @@
<Compile Include="UI\FrmCover.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\FrmIPScan.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\FrmIPScan.Designer.cs">
<DependentUpon>FrmIPScan.cs</DependentUpon>
</Compile>
<Compile Include="UI\FrmProxyCmd.cs">
<SubType>Form</SubType>
</Compile>