Does it also support TCP pings?
As title says, I wonder if it can also work like tcping.exe or it's only based on UDP?
Nope, not yet! Pull requests are welcome, but it would also need to work with Ubuntu and MacOS
Hello @orf thank you for your project, it has been of great help.
I am also interested in TCP ping, this is useful to test app servers head to head. And useful when ICMP is filtered.
I have been using tcpping command doing this in python, and the below code gives a good measurement.
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(timeout)
start = time.monotonic()
s.connect((host, port))
end = time.monotonic()
I asked an LLM and it suggested to use TcpStream::connect_timeout as it said it was portable and did not require elevated privileges it also gave me the following example implementation.
for i in 1..=count {
let start = Instant::now();
let result = addrs.clone().find_map(|a| {
TcpStream::connect_timeout(&a, Duration::from_millis(timeout_ms)).ok()
});
let elapsed = start.elapsed();
match result {
Some(stream) => {
println!("Probe {i}: {:?} ms", elapsed.as_millis());
drop(stream); // explicitly close the socket
}
None => println!("Probe {i}: timeout after {timeout_ms} ms"),
}
}
Before I work on this I have some questions. I am no idea dog when it comes to Rust.
- Would you prefer this to be a separate pinger, or would you want this to be a feature of the pinger?
I've never done anything on Rust, not sure if there are guidelines or best practices I should be aware. 2) Do you have any style guidelines or requirements I must adhere to?
I have submitted a pull request
https://github.com/orf/gping/pull/538
Hey @sanxiago, thanks for this! I’ll take a look this week ❤️