public class ICMPSocket
public class ICMPSocket
var ip = IPAddress.Parse("192.168.2.5"); // var ip = IPAddress.Loopback; using var listener = new ICMPSocket(ip); try { listener.Start(); listener.OnPingReceived += result => { _context?.WriteLine($"{result.MessageType} request received from {result.RemoteEndpoint.Address}"); if (result is PingListenerResultventArgs ping) { ping.PoinsonOperatingSytem = PoinsonOperatingSytem.Linux; } _context?.WriteLine($"{result.MessageType}:{(byte)result.MessageType}"); _context?.WriteLine($"{result.Code}: {result.Code}"); _context?.WriteLine("---------RAW--------"); foreach (var line in result.Data.HexDumps()) { _context?.WriteLine(line); } // Optionally, handle the ping request specifically }; listener.PacketReceived += result => { _context?.WriteLine($"Received {result.Data.Length} bytes from {result.RemoteEndpoint.Address}"); }; listener.Start(); using var ping = new Ping(); var answer = await ping.SendPingAsync(ip, 1000); _context?.WriteLine($"{answer.Status}: Round trip:{answer.RoundtripTime}"); foreach (var line in answer.Buffer.HexDumps()) { _context?.WriteLine(line); } } finally { listener.Stop(); }
System.Object
Walter.Net.Networking.ICMPSocket
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2