-> Bugfix in IPScanner
This commit is contained in:
@@ -8,16 +8,16 @@
|
||||
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" />
|
||||
<TextBox x:Name="tbIPAddressP1" Text="255" HorizontalAlignment="Left" Height="23" Margin="39,58,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="28" KeyDown="ipAddress_KeyDown" TabIndex="0" />
|
||||
<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"/>
|
||||
<TextBox x:Name="maxCountHosts" HorizontalAlignment="Left" Height="24" Margin="258,236,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336" TabIndex="4"/>
|
||||
<TextBox x:Name="calcNetwork" HorizontalAlignment="Left" Height="24" Margin="258,265,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336" TabIndex="5"/>
|
||||
<TextBox x:Name="calcBroadcast" HorizontalAlignment="Left" Height="24" Margin="258,294,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336" TabIndex="6"/>
|
||||
<TextBox x:Name="calcIPRange" HorizontalAlignment="Left" Height="24" Margin="258,323,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336" TabIndex="7"/>
|
||||
<TextBox x:Name="clacMaxNetCount" HorizontalAlignment="Left" Height="24" Margin="258,352,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336" TabIndex="8"/>
|
||||
<TextBox x:Name="nextNumOfHosts" HorizontalAlignment="Left" Height="24" Margin="258,381,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="70" TabIndex="9"/>
|
||||
<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"/>
|
||||
@@ -30,9 +30,9 @@
|
||||
<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" />
|
||||
<TextBox x:Name="tbIPAddressP2" Text="255" HorizontalAlignment="Left" Height="23" Margin="72,58,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="28" KeyDown="ipAddress_KeyDown" TabIndex="1" />
|
||||
<TextBox x:Name="tbIPAddressP3" Text="255" HorizontalAlignment="Left" Height="23" Margin="105,58,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="28" KeyDown="ipAddress_KeyDown" TabIndex="2" />
|
||||
<TextBox x:Name="tbIPAddressP4" Text="255" HorizontalAlignment="Left" Height="23" Margin="138,58,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="28" KeyDown="ipAddress_KeyDown" TabIndex="3" />
|
||||
<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"/>
|
||||
|
||||
@@ -12,98 +12,99 @@ 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;
|
||||
}
|
||||
}
|
||||
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++)
|
||||
{
|
||||
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();
|
||||
}
|
||||
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 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)
|
||||
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)
|
||||
{
|
||||
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;
|
||||
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();
|
||||
}
|
||||
void timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
PopulateListView();
|
||||
}
|
||||
|
||||
private void btnScan_Click(object sender, EventArgs e)
|
||||
{
|
||||
timer.Stop();
|
||||
lvIPList.Items.Clear();
|
||||
private void btnScan_Click(object sender, EventArgs e)
|
||||
{
|
||||
timer.Stop();
|
||||
lvIPList.Items.Clear();
|
||||
|
||||
IPAddress ipFrom = IPAddress.Parse(tbIPRange.Text.Split(new Char[] { '-' })[0]);
|
||||
IPAddress ipFrom = IPAddress.Parse(tbIPRange.Text.Split(new Char[] { '-' })[0]);
|
||||
|
||||
IPAddress ipTo = IPAddress.Parse(ipFrom.GetAddressBytes()[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();
|
||||
}
|
||||
}
|
||||
(tbIPRange.Text.Contains("-") ? byte.Parse(tbIPRange.Text.Split(new Char[] { '-' })[1].ToString()) : ipFrom.GetAddressBytes()[3]));
|
||||
|
||||
results = scanner.BeginScan(ipFrom, ipTo);
|
||||
timer.Interval = 1000;
|
||||
timer.Tick += timer_Tick;
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user