-> IPScanner added

-> PortScanner added
This commit is contained in:
Kevin Krüger
2022-01-17 15:17:34 +01:00
parent 1dc3d93edf
commit bb6c229875
57 changed files with 9227 additions and 26 deletions

View File

@@ -0,0 +1,12 @@
<UserControl x:Class="Networking.Pages.IPScanner"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Networking.Pages"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" Background="White">
<WindowsFormsHost HorizontalAlignment="Left" Height="450" VerticalAlignment="Top" Width="800">
<local:WF_IPScanner/>
</WindowsFormsHost>
</UserControl>

View File

@@ -0,0 +1,63 @@
using IPScanner;
using PTConverter.Plugin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Networking.Pages
{
/// <summary>
/// Interaktionslogik für Networking.xaml
/// </summary>
public partial class IPScanner : UserControl, IPage
{
public IPScanner()
{
InitializeComponent();
}
public string GetCategory() => "";
public UserControl GetPage() => new IPScanner();
public string GetUnderCategory() => "";
string IPtoString(byte[] array)
{
//
// Concatenate all the elements into a StringBuilder.
//
StringBuilder strinbuilder = new StringBuilder();
for (int i = 0; i < array.Count(); i++)
{
strinbuilder.Append(array[i]);
if (i != array.Count() - 1)
strinbuilder.Append('.');
}
return strinbuilder.ToString();
}
private string GetPingTime(IPScanResult result)
{
if (result.ping > -1)
return result.ping + " ms";
return "N/A";
}
}
}

View File

@@ -0,0 +1,41 @@
<UserControl x:Class="Networking.Pages.IPv4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Networking.Pages"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" Background="White">
<Grid>
<ComboBox x:Name="tbNETClass" HorizontalAlignment="Left" Margin="328,61,0,0" VerticalAlignment="Top" Width="266" SelectionChanged="netClassComboBox_SelectedIndexChanged"/>
<TextBox x:Name="tbIPAddressP1" Text="255" HorizontalAlignment="Left" Height="23" Margin="39,58,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="28" KeyDown="ipAddress_KeyDown" />
<ComboBox x:Name="prefixComboBox" HorizontalAlignment="Left" Margin="134,177,0,0" VerticalAlignment="Top" Width="99" Height="28" SelectionChanged="prefixComboBox_SelectedIndexChanged"/>
<ComboBox x:Name="netMaskComboBox" HorizontalAlignment="Left" Margin="328,177,0,0" VerticalAlignment="Top" Width="266" Height="28" SelectionChanged="netMaskComboBox_SelectedIndexChanged"/>
<CheckBox x:Name="firstBitCheckBox" Content="Allow 1st subnet-BIT" HorizontalAlignment="Left" Margin="654,177,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="maxCountHosts" HorizontalAlignment="Left" Height="24" Margin="258,236,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336"/>
<TextBox x:Name="calcNetwork" HorizontalAlignment="Left" Height="24" Margin="258,265,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336"/>
<TextBox x:Name="calcBroadcast" HorizontalAlignment="Left" Height="24" Margin="258,294,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336"/>
<TextBox x:Name="calcIPRange" HorizontalAlignment="Left" Height="24" Margin="258,323,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336"/>
<TextBox x:Name="clacMaxNetCount" HorizontalAlignment="Left" Height="24" Margin="258,352,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336"/>
<TextBox x:Name="nextNumOfHosts" HorizontalAlignment="Left" Height="24" Margin="258,381,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="70"/>
<Label x:Name="noticeLabel" Content="Label" HorizontalAlignment="Left" Margin="134,96,0,0" VerticalAlignment="Top" Height="54" Width="460"/>
<Label Content="Maximum number of Hosts:" HorizontalContentAlignment="Right" HorizontalAlignment="Left" Margin="10,236,0,0" VerticalAlignment="Top" Width="228" Height="24"/>
<Label Content="Network:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="10,265,0,0" VerticalAlignment="Top" Width="228" Height="24"/>
<Label Content="Broadcast:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="10,294,0,0" VerticalAlignment="Top" Width="228" Height="24"/>
<Label Content="IP - range:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="10,323,0,0" VerticalAlignment="Top" Width="228" Height="24"/>
<Label Content="Maximum number of subnets:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="10,352,0,0" VerticalAlignment="Top" Width="228" Height="24"/>
<Label Content="Wanted number of hosts:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="10,381,0,0" VerticalAlignment="Top" Width="228" Height="24"/>
<Label Content="Prefix:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="28,177,0,0" VerticalAlignment="Top" Height="28" Width="101"/>
<Label Content="Netmask:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="243,177,0,0" VerticalAlignment="Top" Height="28" Width="80"/>
<Label Content="IP:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="10,55,0,0" VerticalAlignment="Top" Height="28" Width="24"/>
<Label Content="Network-Type:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="238,58,0,0" VerticalAlignment="Top" Width="90" Height="24"/>
<Button Content="Show next subnet with this number of hosts" x:Name="btnNextSubnet" HorizontalAlignment="Left" Margin="333,383,0,0" VerticalAlignment="Top" Width="261" Click="btnNextSubnet_Click"/>
<TextBox x:Name="tbIPAddressP2" Text="255" HorizontalAlignment="Left" Height="23" Margin="72,58,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="28" KeyDown="ipAddress_KeyDown" />
<TextBox x:Name="tbIPAddressP3" Text="255" HorizontalAlignment="Left" Height="23" Margin="105,58,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="28" KeyDown="ipAddress_KeyDown" />
<TextBox x:Name="tbIPAddressP4" Text="255" HorizontalAlignment="Left" Height="23" Margin="138,58,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="28" KeyDown="ipAddress_KeyDown" />
<Label Content=".
" HorizontalAlignment="Left" Margin="68,59,0,0" Padding="0" VerticalAlignment="Top" Width="3"/>
<Label Content=". " HorizontalAlignment="Left" Margin="101,59,0,0" Padding="0" VerticalAlignment="Top" Width="3"/>
<Label Content=". " HorizontalAlignment="Left" Margin="134,59,0,0" Padding="0" VerticalAlignment="Top" Width="3"/>
</Grid>
</UserControl>

View File

@@ -0,0 +1,339 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using NetCalc;
using PTConverter.Plugin;
namespace Networking.Pages
{
/// <summary>
/// Interaktionslogik für Networking.xaml
/// </summary>
public partial class IPv4 : UserControl, IPage
{
#region Declarations
protected IPTool ip = null;
protected bool fill = false; // lock events wenn updating
protected bool isIP = false;
#endregion
private string _ipAddress = "0.0.0.0";
private string IPAddress { get => tbIPAddressP1.Text + "." + tbIPAddressP2.Text + "." + tbIPAddressP3.Text + "." + tbIPAddressP4.Text; set => _ipAddress = value; }
public IPv4()
{
InitializeComponent();
tbNETClass.ItemsSource = new object[] {
"Class A: 0.0.0.0-127.255.255.255",
"Class B: 128.0.0.0-191.255.255.255",
"Class C: 192.0.0.0-223.255.255.255",
"Class D: 224.0.0.0-239.255.255.255",
"Class E: 240.0.0.0-254.255.255.255"};
tbNETClass.SelectedIndex = 0;
}
public string GetCategory() => "Networking";
public string GetUnderCategory() => "IPv4";
public UserControl GetPage() => new IPv4();
#region Methods Used
protected void newIP()
{
try
{
ip = new IPTool(IPAddress);
fillIPCalc();
}
catch (Exception e)
{
MessageBox.Show(e.StackTrace);
}
//catch (UnknownHostException e)
//{
// main.getJp_Calc().getJtf_IP_Calc().setBackground(java.awt.Color.red);
//}
}
protected void fillIPCalc()
{
if (ip == null || ip.getIp() == null) return;
this.fill = true;
this.fillComboBox_Prefix();
this.fillComboBox_NetworkMask();
// Prefix
int prefix = ip.getNetworkPrefix();
if (prefix >= 8 && prefix <= 30)
{
if (prefix != ip.getNetworkClassPrefix() && !ip.isFirstSubNetBit()) prefix--;
prefix = prefix - ip.getNetworkClassPrefix();
}
else prefix = -1;
prefixComboBox.SelectedIndex = prefix;
// NetMask
netMaskComboBox.SelectedIndex = prefix;
// folgendes nur wenn Netzwerkmaske vorhanden
// nicht der Fall bei Class-D oder E
if (prefix != -1)
{
// max Net Hosts
maxCountHosts.Text = ip.getMaxNetworkHosts() + "";
// Net Class
calcNetwork.Text = ip.getNetworkClassName();
// Broadcast
calcBroadcast.Text = ip.getBroadCast();
// Network
calcNetwork.Text = ip.getNetwork();
// Net-Class
tbNETClass.SelectedIndex = ip.getNetworkClass();
// IP-Range
string[] ipRange = ip.getNetworkIPRange();
calcIPRange.Text = ipRange[0] + " - " + ipRange[1];
// max Sub-Nets
clacMaxNetCount.Text = ip.getMaxSubNets() + "";
}
else // Anzeige löschen
{
// max Net Hosts
maxCountHosts.Text = "";
// Net Class
calcNetwork.Text = "";
// Broadcast
calcBroadcast.Text = "";
// Network
calcNetwork.Text = "";
// IP-Range
calcIPRange.Text = "";
// max Sub-Nets
clacMaxNetCount.Text = "";
}
// Description
string desc = "";
if (ip.get1Byte() >= (byte)64 && ip.getNetworkClass() == (byte)0) // 64.
desc = "reserved for future use";
if (ip.get1Byte() == (byte)127) // localhost
desc = "localhost and loopback-Device - your one computer";
if (ip.get1Byte() == (byte)10) // private 10.0.0.0
desc = "private net - for internal use only, would not be routed in internet";
if (ip.get1Byte() == (byte)192 && ip.get2Byte() == (byte)168) // private 192. - 168.
desc = "private net - for internal use only, would not be routed in internet";
if (ip.get1Byte() == (byte)172 && (ip.get2Byte() >= (byte)16 && ip.get2Byte() <= (byte)31)) //private 172.16 - 172.31
desc = "private net - for internal use only, would not be routed in internet";
if ((ip.get1Byte() == (byte)169) && (ip.get2Byte() == (byte)254)) // 169.254.
desc = "APIPA Automatic Private IP Addressing";
if (ip.get1Byte() == (byte)0) // 0.
desc = "0.0.0.0 = default route";
if (ip.getNetworkClass() == (byte)4) // Class-E
desc = "reserved for future use";
if (ip.getNetworkClass() == (byte)3) // Class-D
desc = "used for multicast";
noticeLabel.Content = "Info stuff: " + desc;
this.fill = false;
}
protected void fillComboBox_Prefix()
{
if (ip == null || ip.getIp() == null) return;
prefixComboBox.Items.Clear();
if (ip.getNetworkClassPrefix() == -1)
{
prefixComboBox.Items.Add("");
return;
}
int startPrefix = ip.getNetworkClassPrefix();
// first is Networkclass
prefixComboBox.Items.Add(startPrefix + "");
startPrefix++;
if (!ip.isFirstSubNetBit()) startPrefix++;
for (int i = startPrefix; i <= 30; i++)
prefixComboBox.Items.Add(i + "");
}
protected void fillComboBox_NetworkMask()
{
if (ip == null || ip.getIp() == null) return;
netMaskComboBox.Items.Clear();
if (ip.getNetworkClassPrefix() == -1)
{
netMaskComboBox.Items.Add("");
return;
}
int startPrefix = ip.getNetworkClassPrefix();
// first is Networkclass
netMaskComboBox.Items.Add(ip.getNetworkMaskByPrefix(startPrefix));
startPrefix++;
if (!ip.isFirstSubNetBit()) startPrefix++;
for (int i = startPrefix; i <= 30; i++)
netMaskComboBox.Items.Add(ip.getNetworkMaskByPrefix(i));
}
#endregion
#region Events
private void ipAddress_Leave(object sender, System.EventArgs e)
{
newIP();
}
private void ipAddress_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
newIP();
}
}
private void prefixComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (ip == null || ip.getIp() == null || fill) return;
if (ip.getNetworkClassPrefix() == -1) return;
int prefix = Int32.Parse((string)prefixComboBox.SelectedItem);
ip.setNetworkPrefix(prefix);
fillIPCalc();
}
private void netMaskComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (ip == null || ip.getIp() == null || fill) return;
if (ip.getNetworkClassPrefix() == -1) return;
int select = netMaskComboBox.SelectedIndex;
int prefix = select + ip.getNetworkClassPrefix();
if (select != 0 && !ip.isFirstSubNetBit()) prefix++;
//int prefix = Integer.parseInt((String)main.getJcb_Calc_NetworkMask().getSelectedItem());
ip.setNetworkPrefix(prefix);
fillIPCalc();
}
private void netClassComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (fill) return;
switch (tbNETClass.SelectedIndex)
{
case 0:
IPAddress = "1.0.0.1";
break;
case 1:
IPAddress = "128.0.0.1";
break;
case 2:
IPAddress = "192.0.0.1";
break;
case 3:
IPAddress = "224.0.0.1";
break;
case 4:
IPAddress = "240.0.0.1";
break;
}
newIP();
}
private void firstBitCheckBox_CheckedChanged(object sender, System.EventArgs e)
{
if (ip == null || ip.getIp() == null || fill) return;
ip.setFirstSubNetBit((bool)firstBitCheckBox.IsChecked);
fillIPCalc();
}
private void nextSubnetButt_Click(object sender, System.EventArgs e)
{
if (ip == null || ip.getIp() == null || fill) return;
///nextNumOfHosts.BackColor = Color.White;
try
{
int hosts = Int32.Parse(nextNumOfHosts.Text);
IPTool newIp = ip.getNextSubNet(hosts);
if (newIp == null)
{
//ToManyHosts
noticeLabel.Content = "Info stuff: Number of hosts in this network-class not possible!";
return;
}
ip = newIp;
IPAddress = ip.getIp();
}
catch (System.FormatException)
{
//nextNumOfHosts.BackColor = Color.Red;
return;
}
catch (Exception e1)
{
MessageBox.Show(e1.StackTrace);
return;
}
fillIPCalc();
}
private void calcButt_Click(object sender, System.EventArgs e)
{
newIP();
}
#endregion
private void btnNextSubnet_Click(object sender, RoutedEventArgs e)
{
if (ip == null || ip.getIp() == null || fill) return;
try
{
int hosts = Int32.Parse(nextNumOfHosts.Text);
IPTool newIp = ip.getNextSubNet(hosts);
if (newIp == null)
{
//ToManyHosts
noticeLabel.Content = "Info stuff: Number of hosts in this network-class not possible!";
return;
}
ip = newIp;
IPAddress = ip.getIp();
}
catch (System.FormatException)
{
//nextNumOfHosts.BackColor = Color.Red;
return;
}
catch (Exception e1)
{
MessageBox.Show(e1.StackTrace);
return;
}
fillIPCalc();
}
}
}

View File

@@ -0,0 +1,12 @@
<UserControl x:Class="Networking.Pages.PortScanner"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Networking.Pages"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" Background="White">
<Grid>
</Grid>
</UserControl>

View File

@@ -0,0 +1,35 @@
using PTConverter.Plugin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Networking.Pages
{
/// <summary>
/// Interaktionslogik für Networking.xaml
/// </summary>
public partial class PortScanner : UserControl, IPage
{
public PortScanner()
{
InitializeComponent();
}
public string GetCategory() => "Networking";
public UserControl GetPage() => new PortScanner();
public string GetUnderCategory() => "PortScan";
}
}

133
Networking/Pages/WF_IPScanner.Designer.cs generated Normal file
View File

@@ -0,0 +1,133 @@
namespace Networking.Pages
{
partial class WF_IPScanner
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Komponenten-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.lvIPList = new System.Windows.Forms.ListView();
this.chIP = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chPing = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chHost = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chRecognized = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.btnScan = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.tbIPRange = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// lvIPList
//
this.lvIPList.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.lvIPList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.chIP,
this.chPing,
this.chHost,
this.chRecognized});
this.lvIPList.FullRowSelect = true;
this.lvIPList.HideSelection = false;
this.lvIPList.Location = new System.Drawing.Point(12, 87);
this.lvIPList.MultiSelect = false;
this.lvIPList.Name = "lvIPList";
this.lvIPList.Size = new System.Drawing.Size(714, 282);
this.lvIPList.TabIndex = 1;
this.lvIPList.UseCompatibleStateImageBehavior = false;
this.lvIPList.View = System.Windows.Forms.View.Details;
//
// chIP
//
this.chIP.Text = "IP";
this.chIP.Width = 93;
//
// chPing
//
this.chPing.Text = "Ping";
//
// chHost
//
this.chHost.Text = "Host";
this.chHost.Width = 88;
//
// chRecognized
//
this.chRecognized.Text = "Recognized as";
this.chRecognized.Width = 119;
//
// btnScan
//
this.btnScan.Location = new System.Drawing.Point(323, 58);
this.btnScan.Name = "btnScan";
this.btnScan.Size = new System.Drawing.Size(75, 23);
this.btnScan.TabIndex = 7;
this.btnScan.Text = "Scan";
this.btnScan.UseVisualStyleBackColor = true;
this.btnScan.Click += new System.EventHandler(this.btnScan_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(9, 64);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(50, 13);
this.label1.TabIndex = 6;
this.label1.Text = "IP range:";
//
// tbIPRange
//
this.tbIPRange.Location = new System.Drawing.Point(66, 61);
this.tbIPRange.Name = "tbIPRange";
this.tbIPRange.Size = new System.Drawing.Size(251, 20);
this.tbIPRange.TabIndex = 8;
//
// WF_IPScanner
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.tbIPRange);
this.Controls.Add(this.btnScan);
this.Controls.Add(this.label1);
this.Controls.Add(this.lvIPList);
this.Name = "WF_IPScanner";
this.Size = new System.Drawing.Size(800, 450);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ListView lvIPList;
private System.Windows.Forms.ColumnHeader chIP;
private System.Windows.Forms.ColumnHeader chPing;
private System.Windows.Forms.ColumnHeader chHost;
private System.Windows.Forms.ColumnHeader chRecognized;
private System.Windows.Forms.Button btnScan;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox tbIPRange;
}
}

View File

@@ -0,0 +1,109 @@
using IPScanner;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Networking.Pages
{
public partial class WF_IPScanner : UserControl
{
NetworkScanner scanner = new NetworkScanner();
Timer timer = new Timer();
List<IPScanResult> results;
public WF_IPScanner()
{
InitializeComponent();
List<Tuple<IPAddress, IPAddress>> ipRanges = IPRanges.GetOperationalIPRanges();
if (ipRanges.Count > 0)
{
//tbIPRange.Text = ipRanges[0].Item1.GetAddressBytes().ToString();
tbIPRange.Text = IPtoString(ipRanges[0].Item1.GetAddressBytes()) + "-" + ipRanges[0].Item2.GetAddressBytes()[3].ToString();
// ipTo.IPAddress = ipRanges[0].Item2;
}
}
string IPtoString(byte[] array)
{
//
// Concatenate all the elements into a StringBuilder.
//
StringBuilder strinbuilder = new StringBuilder();
for (int i = 0; i < array.Count(); i++)
{
strinbuilder.Append(array[i]);
if (i != array.Count() - 1)
strinbuilder.Append('.');
}
return strinbuilder.ToString();
}
private string GetPingTime(IPScanResult result)
{
if (result.ping > -1)
return result.ping + " ms";
return "N/A";
}
private void PopulateListView()
{
bool itemModified = false;
for (int i = 0; i < results.Count; i++)
{
IPScanResult result = results[i];
if (result.status == ScanStatus.Complete || result.status == ScanStatus.Partial)
{
string ip = result.ip.ToString();
ListViewItem[] matchedItems = lvIPList.Items.Find(ip, false);
if (matchedItems.Length > 0)
{
matchedItems[0].Tag = result.response;
matchedItems[0].SubItems[0].Text = result.ip.ToString();
matchedItems[0].SubItems[1].Text = GetPingTime(result);
matchedItems[0].SubItems[2].Text = result.host;
matchedItems[0].SubItems[3].Text = result.identification;
}
else
{
ListViewItem lvi = new ListViewItem(new string[] { result.ip.ToString(), GetPingTime(result), result.host, result.identification });
lvi.Name = ip;
lvIPList.Items.Add(lvi);
}
itemModified = true;
}
}
}
void timer_Tick(object sender, EventArgs e)
{
PopulateListView();
}
private void btnScan_Click(object sender, EventArgs e)
{
timer.Stop();
lvIPList.Items.Clear();
IPAddress ipFrom = IPAddress.Parse(tbIPRange.Text.Split(new Char[] { '-' })[0]);
IPAddress ipTo = IPAddress.Parse(ipFrom.GetAddressBytes()[0] + "." +
ipFrom.GetAddressBytes()[1] + "." +
ipFrom.GetAddressBytes()[2] + "." +
byte.Parse(tbIPRange.Text.Split(new Char[] { '-' })[1].ToString()));
results = scanner.BeginScan(ipFrom, ipTo);
timer.Interval = 1000;
timer.Tick += timer_Tick;
timer.Start();
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>