I am trying to get the IP's of devices attached to my network(WLAN to which i am connected) .Firstly i used Command Line in Win8 and pinging there serially while knowing my own IP (incrementing it each time and pinging ) .To get programmatically do it like WnetWatcher I am utilizing Ping Class by calling a function passing attempts=4
and timeout=3
but a blue screen saying PROCESS_HAS_BLOCKED_PAGES
and found it an underlying API issue. Anyone has a better idea than this to get all the devices IP's because several threads at SO finds it using Dns
Class but that works for a single PC(mine) .
1). What is the laternate of Ping
and if it's Ping
then how to get around API issue.
2).Also, how can i get the Router IP ,so that I maybe able to run the loop for other IP's on an network or is there any better alternative to it?
public static void Ping(string host, int attempts, int timeout) {
new Thread(delegate()
{
try
{
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
ping.PingCompleted += new PingCompletedEventHandler(PingCompleted);
ping.SendAsync(host, timeout, host);
}
catch
{
// Do nothing and let it try again until the attempts are exausted.
// Exceptions are thrown for normal ping failurs like address lookup
// failed. For this reason we are supressing errors.
}
}).Start();
}
private static void PingCompleted(object sender, PingCompletedEventArgs e)
{
string ip = (string)e.UserState;
if (e.Reply != null && e.Reply.Status == IPStatus.Success)
{
// Logic for Ping Reply Success
// Console.WriteLine(String.Format("Host: {0} ping successful", ip));
lstlocal.listViewItem //Error ...the intellisense is not accepting it here
}
else
{
// Logic for Ping Reply other than Success
}
}
//function caller code from a button
lstLocal.Items.Clear();
lstLocal.FullRowSelect = true;
bool value;
for (int i = 0; i <= 254; i++)
{
string ping_var = "192.168.1" + "." + i;
value = Ping(ping_var, 4, 3);
// MessageBox.Show("Ping response for"+ping_var +"is" + value);
if(value==true)
{
ListViewItem items=new ListViewItem(ping_var.ToString());
lstLocal.Items.Add(items);
}
}
}