-> Bugfix in IPScanner
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
private void btnScan_Click(object sender, EventArgs e)
|
||||
{
|
||||
timer.Stop();
|
||||
lvIPList.Items.Clear();
|
||||
void timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
PopulateListView();
|
||||
}
|
||||
|
||||
IPAddress ipFrom = IPAddress.Parse(tbIPRange.Text.Split(new Char[] { '-' })[0]);
|
||||
private void btnScan_Click(object sender, EventArgs e)
|
||||
{
|
||||
timer.Stop();
|
||||
lvIPList.Items.Clear();
|
||||
|
||||
IPAddress ipTo = IPAddress.Parse(ipFrom.GetAddressBytes()[0] + "." +
|
||||
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();
|
||||
}
|
||||
}
|
||||
(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