L3 devices can often be detected via a trace route command. L2 devices can be completely invisible, although with some vendors, Cisco included, have special L2 protocols that might be active which will reveal them or they might have something like SNMP active, which might also reveal them. Non-managed switches and hubs usually require tracing the cables. There are some "network discovery" products that will use multiple approaches to attempt to discover what the network looks like.