I have following C# code for pinging an IP, and writing the result to a log.
private async ValueTask PingMachine() {
var timesToPing = 4;
var counter = 1;
while (counter <= timesToPing) {
var reply = await Pinger();
foreach (var r in reply) {
TagService.log_PLC.AppendLine($" Pinged {TagService.IP_PLC_List} {counter} times time:{r.RoundtripTime} status: {r.Status.ToString()}");
}
}
counter++;
}
private async Task<IEnumerable<PingReply>> Pinger() {
List<string> addresses = new List<string>();
if (Check_IP_Correct(TagService.IP_PLC_List) == true) {
addresses.Add(TagService.IP_PLC_List);
}
var tasks = addresses.Select(async ip => await new Ping().SendPingAsync(ip, 1000));
var reply = await Task.WhenAll(tasks);
return reply;
}
When I ping an IP that is online normally there is no problem, but when I ping a specific IP that is unreachable for testing, I get always following in the log. (3 times TimedOut
, the fourth reply is always DestinationHostUnreachable
Pinged 10.92.XXX.XX 1 times time:0 status: TimedOut
Pinged 10.92.XXX.XX 2 times time:0 status: TimedOut
Pinged 10.92.XXX.XX 3 times time:0 status: TimedOut
Pinged 10.92.XXX.XX 4 times time:0 status: DestinationHostUnreachable
When I do the test in the same server with the same IP, but this time directly in the command line I always get a reply like Destination host unreachable
.
Reply from 100.72.XXX.XX: Destination host unreachable.
Reply from 100.72.XXX.XX: Destination host unreachable.
Reply from 100.72.XXX.XX: Destination host unreachable.
Reply from 100.72.XXX.XX: Destination host unreachable.
I think the replies in the command lines should be correct. Why am I getting different replies with my code? What could be wrong?