gping icon indicating copy to clipboard operation
gping copied to clipboard

Does it also support TCP pings?

Open OpsecGuy opened this issue 2 years ago • 4 comments

As title says, I wonder if it can also work like tcping.exe or it's only based on UDP?

OpsecGuy avatar Jul 30 '23 10:07 OpsecGuy

Nope, not yet! Pull requests are welcome, but it would also need to work with Ubuntu and MacOS

orf avatar Jul 31 '23 10:07 orf

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.

  1. 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?

sanxiago avatar Aug 21 '25 15:08 sanxiago

I have submitted a pull request

https://github.com/orf/gping/pull/538

sanxiago avatar Aug 23 '25 01:08 sanxiago

Hey @sanxiago, thanks for this! I’ll take a look this week ❤️

orf avatar Aug 23 '25 10:08 orf