Post: C# Help with Ping
11-17-2014, 09:39 PM #1
ItsAvees
Bounty hunter
(adsbygoogle = window.adsbygoogle || []).push({}); Hi guys, so I am having some trouble pinging asynchronously. I am getting this error :

    [I][B]cannot implicitly convert type void to system.net.networkinformation.pingreply [/B][/I]


This is my Code :

    private void IPlook_Tick(object sender, EventArgs e)
{

Properties.Settings.Default.nextIP += 1;

if (Properties.Settings.Default.nextIP >= 255)
{
IPlook.Stop();
}

string IP = "192.168.0." + Properties.Settings.Default.nextIP.ToString();
CurIP.Text = IP;

//See if online
try
{
byte[] buffer = new Byte[10];
PingOptions options = new PingOptions();
string textLabel = "";

Ping ping = new Ping();
PingReply reply = ping.SendAsync(IP, 100, buffer, options);


if (reply.Status == IPStatus.Success)
{
string Hostname = Dns.GetHostByAddress(IP).HostName;
dataGridView1.Rows.Add(Hostname, IP, "Online");
}
else
{
}

}
catch (Exception er)
{
MessageBox.Show("Something Went Wrong", "Error Alert", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}


Please Help :Z
11-17-2014, 09:55 PM #2
ItsAvees
Bounty hunter
pls :'(
11-18-2014, 07:18 AM #3
can you take it to pastebin?
11-21-2014, 01:35 AM #4
Pichu
RIP PICHU.
Originally posted by ItsAvees View Post
Hi guys, so I am having some trouble pinging asynchronously. I am getting this error :

    [I][B]cannot implicitly convert type void to system.net.networkinformation.pingreply [/B][/I]


This is my Code :

    private void IPlook_Tick(object sender, EventArgs e)
{

Properties.Settings.Default.nextIP += 1;

if (Properties.Settings.Default.nextIP >= 255)
{
IPlook.Stop();
}

string IP = "192.168.0." + Properties.Settings.Default.nextIP.ToString();
CurIP.Text = IP;

//See if online
try
{
byte[] buffer = new Byte[10];
PingOptions options = new PingOptions();
string textLabel = "";

Ping ping = new Ping();
PingReply reply = ping.SendAsync(IP, 100, buffer, options);


if (reply.Status == IPStatus.Success)
{
string Hostname = Dns.GetHostByAddress(IP).HostName;
dataGridView1.Rows.Add(Hostname, IP, "Online");
}
else
{
}

}
catch (Exception er)
{
MessageBox.Show("Something Went Wrong", "Error Alert", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}


Please Help :Z


You must login or register to view this content.
You must login or register to view this content.

Everything you need to know is here.
11-21-2014, 03:40 AM #5
jagex
Gym leader
No point in having catch (Exception er) if you write out your own custom message, can just do catch{}

can you send me your source code so I can look at it, I can try to help you

My best guess is that the problem is somewhere here, PingReply reply = ping.SendAsync(IP, 100, buffer, options);

"cannot implicitly convert type void to system.net.networkinformation.pingreply"

maybe your variable IP is empty and thats why its giving you that it cannot convert void to system.net.networkinformation.pingreply
Last edited by jagex ; 11-21-2014 at 03:45 AM.
11-22-2014, 10:11 PM #6
Jakes625
Trippy Hippy
Originally posted by ItsAvees View Post
Hi guys, so I am having some trouble pinging asynchronously. I am getting this error :

    [I][B]cannot implicitly convert type void to system.net.networkinformation.pingreply [/B][/I]


This is my Code :

    private void IPlook_Tick(object sender, EventArgs e)
{

Properties.Settings.Default.nextIP += 1;

if (Properties.Settings.Default.nextIP >= 255)
{
IPlook.Stop();
}

string IP = "192.168.0." + Properties.Settings.Default.nextIP.ToString();
CurIP.Text = IP;

//See if online
try
{
byte[] buffer = new Byte[10];
PingOptions options = new PingOptions();
string textLabel = "";

Ping ping = new Ping();
PingReply reply = ping.SendAsync(IP, 100, buffer, options);


if (reply.Status == IPStatus.Success)
{
string Hostname = Dns.GetHostByAddress(IP).HostName;
dataGridView1.Rows.Add(Hostname, IP, "Online");
}
else
{
}

}
catch (Exception er)
{
MessageBox.Show("Something Went Wrong", "Error Alert", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}


Please Help :Z



    PingReply reply = ping.SendAsync(IP, 100, buffer, options);

That is your issue.

ping.SendAsync() is a method with no return type.
11-22-2014, 10:23 PM #7
ItsAvees
Bounty hunter
Originally posted by Jakes625 View Post
    PingReply reply = ping.SendAsync(IP, 100, buffer, options);

That is your issue.

ping.SendAsync() is a method with no return type.


So how would I get the returned value?
11-23-2014, 02:07 AM #8
Jakes625
Trippy Hippy
Originally posted by ItsAvees View Post
So how would I get the returned value?


use a different method. That is the equivalent of:
    public void test(){
//do stuff
}
11-23-2014, 11:35 PM #9
jagex
Gym leader
This worked for me

    
private async Task Pinger()
{

var ip = IPAddress.Parse("184.150.152.168");
pingSender.PingCompleted += pingFinished;
pingSender.SendAsync(ip, 100);



}

private void pingFinished(object sender, PingCompletedEventArgs e)
{

if (e.Reply.Status == IPStatus.Success)
{
MessageBox.Show("Ping Sucess");
}




}

The following user thanked jagex for this useful post:

ItsAvees

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo