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