News for hackers. Stuff that matters.
Re:Show HN: Whosthere: A LAN discovery tool with a modern TU... by rvermeulen98 on Friday January 23, 2026 @09:46AM (#46733101)
Thanks, I am glad you like it! I couldn't find a Go API that just returns the OS "default" network interface, so struggled a bit with a correct implementation for that part.

When reading some blog posts, I found often a solution where it sends out an UDP dial to for example 8.8.8.8:53 because you can then get the network interface back from the connection it's local address. As fallback I implemented to pick the first non-loopback interface that is up.

Would be open to suggestions to do this in a better way!

Re:Show HN: Whosthere: A LAN discovery tool with a modern TU... by fellerts on Friday January 23, 2026 @09:59AM (#46733263)
I think this package does exactly what you need: https://pkg.go.dev/github.com/google/gopacket/routing. Works on my machine (error handling left to the reader)

    router, _ := routing.New()
    iface, _, _, _ := router.Route(net.ParseIP("8.8.8.8"))
    fmt.Println(iface.Name)
this prints my Ethernet interface as expected. It doesn't make any requests, it just figures out where to route a packet. I guess it interfaces with the OS routing table.
Re:Show HN: Whosthere: A LAN discovery tool with a modern TU... by rvermeulen98 on Friday January 23, 2026 @10:30AM (#46733673)
Thanks for sharing! This is definitely something I will look into, I am all in favor to simplify the current implementation of finding the "default" OS network interface.
Re:Show HN: Whosthere: A LAN discovery tool with a modern TU... by contingencies on Friday January 23, 2026 @12:46PM (#46735386)
You'd better use the default route and not some random IP, particularly DNS IPs which people often meddle with.

  # IPv4 default route only
  uname
  Darwin$ route -n get 0.0.0.0 | grep interface | cut -d ':' -f2
  Linux$ route -nv  |grep ^0.0.0.0 | awk '{print $NF}'