Untitled
unknown
plain_text
3 months ago
1.1 kB
4
Indexable
string target = "google.com"; int maxHops = 30; int timeout = 3000; Console.WriteLine($"Tracing route to {target} with max {maxHops} hops:\n"); Console.ReadLine(); using (Ping pingSender = new Ping()) { for (int ttl = 1; ttl <= maxHops; ttl++) { PingOptions options = new PingOptions(ttl, true); byte[] buffer = new byte[32]; // default ping buffer PingReply reply; try { reply = pingSender.Send(target, timeout, buffer, options); } catch (Exception ex) { Console.WriteLine($"{ttl}\tError: {ex.Message}"); continue; } string address = reply?.Address?.ToString() ?? "*"; Console.Write($"{ttl}\t{address}\t"); if (reply.Status == IPStatus.TtlExpired || reply.Status == IPStatus.Success) { Console.WriteLine($"[{reply.RoundtripTime} ms]"); } else { Console.WriteLine(reply.Status); } if (reply.Status == IPStatus.Success) { break; } } }
Editor is loading...
Leave a Comment