pro-bing icon indicating copy to clipboard operation
pro-bing copied to clipboard

Allow setting TTL

Open Hipska opened this issue 2 years ago • 5 comments

This in order to implement traceroute-like tools..

Hipska avatar Mar 21 '23 16:03 Hipska

TTL is already supported.

SuperQ avatar Mar 21 '23 17:03 SuperQ

A traceroute tool would be interesting. I've been thinking about a "traceroute discovery" option for the smokeping_prober.

SuperQ avatar Mar 21 '23 17:03 SuperQ

@SuperQ seems like the app keeps hanging when you set a low TTL, the Run method never returns.. https://gist.github.com/Hipska/6c19e707445029cae8abfac098405032

Hipska avatar May 28 '24 07:05 Hipska

I'm building a tool to run some automated pings on Windows. I'm not even using ctx, I see that it simply blocks forever when setting a TTL of 1 and calling Run().

EDIT: Same behavior on WSL/ubuntu

tt2468 avatar May 29 '24 20:05 tt2468

I've been playing with sending ICMP pings with Go (not using any library). I was having problems with TTL on Windows as well, and wanted to see how this library does it (as it's widely used). This line: https://github.com/prometheus-community/pro-bing/blob/59a8668c6f8370474a07d6baa3810b50c668c1a5/packetconn.go#L56-L59 attempts to enable TTL and https://github.com/prometheus-community/pro-bing/blob/59a8668c6f8370474a07d6baa3810b50c668c1a5/packetconn.go#L77 to set the actual TTL value.

Though the first explicitly ignores errors for Windows, as if you print error, Windows does not support settings flags on the socket in this way. Digging in, https://github.com/golang/go/issues/7175 is the tracker to support it. There was an effort back in 2017/2018, but never landed.

For those just calling this library and say it's hanging forever, it's because of this: https://github.com/prometheus-community/pro-bing/blob/59a8668c6f8370474a07d6baa3810b50c668c1a5/ping.go#L107, if you just set an overall timeout, it will exit without waiting for all responses.

The funny bit is that the SetTTL method does seem to half-work on Windows, but the default firewall is blocking you. I fired up WireShark and watched what was going on, and you can see the TTL is set on the ECHO Request. Plus the ECHO Reply is actually there (with a TTL Exceeded error). The problem is that Windows doesn't pass this packet on to your app (potentially because of the failed SetControlMessage(FlagTTL) call). If you create a Windows Firewall rule (inbound rule, custom type, protocol: ICMPv4, allowing the connection), the TTL Exceeded message will actually make its way to your app and work as expected. As this isn't ideal if you distribute your app, it's not a great workaround (unless you had an installer add the firewall rule or something like that).

A semi-terrible workaround is to use WSL2 instead. Since the Linux impl for Control message and TTL works on Linux, and Windows properly translates this to their socket types, it may work. So just run this as a Linux app on Windows (using WSL), and it may do what you need.

jwendel avatar Jun 18 '25 13:06 jwendel