Is there a free Linux software to determine if two network devices are connected? A php class can be also good...

I'd like to draw the network topology. I can determine the devices in the network with zenmap (it saves the results to file), but I don't know which device connected to which device... (zenmap can also draw topology, but it doesn't save it to file)

  • 1
    @kungfusia, can you elaborate on what problem you could solve with this information? Apr 24, 2011 at 9:40

3 Answers 3


It sounds like you're trying "map out" a network, going from zero knowledge of what's "out there" to a full knowledge of every device that is reachable from a given point.

Linux commands like ethtool can tell you whether or not your interfaces are physically connected to something else. So that's a good start. Of course, if the thing you are connected to is a router or switch, then you've got additional work to do.

This is actually a deep and complex problem. There isn't a universally recognized "hey, I'm here" protocol other than ping, which is often disabled for security reasons.

Continuning, however, the next thing to work from is your current subnet mask. That should tell you the range of IP addresses that it's possible to communicate with out of that interface. Scanning every possible IP address of a subnet is generally the most reliable way to do this (using a tool like nmap to accomplish it). It's best if a protocol exists to support this purpose, like ping, CDP for Cisco devices, or LLTD for Windows Vista/XP systems.

If you are in a situation where you are dealing with multiple LAN routers, then you can use routes in the FIB (the route or ip route show command), to learn about other subnets that should be indirectly reachable. You then have additional known-reachable IP ranges to scan.

However, if we are talking about the entire Internet, or a very large subnet, then this becomes impractical. In that case a workable solution is generally to rely on "discovery" or "rendezvous" services such as IGMP or Bonjour. You are then at the mercy of only knowing about devices that wish to be known about. But this is better than trying to port scan the entire Internet.


traceroute may be a good start: it shows you the number of hops between your own host and a remote. I don't know of a way to get this kind of info for a pair of remotes, except by running traceroute on one of them.

  • Thank you for your answer! In my opinion tracerout can only show the hops between routers... but I'd like to know where is a host, or a switch also.
    – kungfucsiga
    Mar 11, 2011 at 14:17

If your device list includes IP addresses and netmasks, you could create a basic layer 3 graph by creating a vertex for each subnet, a vertex for each device, and an edge between each (subnet, device) in your device list.

This will result in a pure layer-3 topology which probably isn't a bad start. Also if your network is somewhat complex, this won't work too well. For example, if you have duplicate or overlapping subnets (perhaps with NAT or MPLS VPNs), the assumption that all devices within a particular IP range are connected may not be true.

  • Thank you for your answer! But how can I do this in practice? (what command should I use, or what software should I use)
    – kungfucsiga
    Mar 11, 2011 at 14:14

You must log in to answer this question.