Hi,
I am trying to make a program that is going to ping through my LAN.
I have the following code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;
namespace ScanLAN
{
public partial class frmScan : Form
{
public frmScan()
{
InitializeComponent();
}
private void frmScan_Load(object sender, EventArgs e)
{
for (int subnet = 1; subnet < 254; subnet++)
PingLAN("192.168.1." + subnet);
}
private void PingLAN(string IP)
{
try
{
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(IP, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine("Address: {0}", reply.Address.ToString());
Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
}
else
{
Console.WriteLine(IP + " - No Reply");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
The problem is, if I press the stop debugging button while it is running, most of the time my computer crashes to a BSOD. Does anyone know why this is happening and how I can sort it?