how can i send a ping request with a specific size of bytes, the same as determining the -l when sending ping through the command line. can you give me an example?
also can i determine the amount of packets that the ping sends? like the -n on the command line.
thanks :)
Type "ping -s " and press enter. Windows users will need to use "-l" instead of "-s." The default packet size is 56 bytes for Linux and Mac pings, and 32 bytes in Windows. The actual packet size will be slightly larger than what you enter due to the addition of the ICMP header information attached to the ping.
Type "-l" followed by a space, then a numeric value indicating the size of each data packet you wish to send, measured in bytes (the default is "32"). For example, type "ping -l 64" into the command prompt to adjust the size of each data packet to 64 bytes.
Ping Packet Size In the above example, when we set the packet size to 100, it displays '128 bytes' in the output. This is because of the Ping packet header size, which is 28 bytes. So, if you specify the packet size as 100, 28 bytes for header will be added to it and 128 bytes will be sent.
Though the default ping packet size is 32 bytes, we can change it by a simple command while pinging a destination from your computer. By using -l option, you can decide the size of the echo request packets. The valid value of the size of ICMP packets is from 0 to 65500.
You can use the System.Net.NetworkInformation.Ping class to send ICMP echo requests. It gives you complete control over the packet size and the number of packets sent:
using System.Net.NetworkInformation;
public void PingHost(string host, int packetSize, int packetCount)
{
int timeout = 1000; // 1 second timeout.
byte[] packet = new byte[packetSize];
// Initialize your packet bytes as you see fit.
Ping pinger = new Ping();
for (int i = 0; i < packetCount; ++i) {
pinger.Send(host, timeout, packet);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With