Initial Setup
As a Linux administrator you have installed a fresh Linux box with 6 NICs eth0 to eth5. The eth0 interface is correctly configured and all other interfaces are currently up but without IP address. The network guys have simply attached four cables to this box. Two LAN cables are used to connect the box to the production network and two are used to connect the box to a private network. You only know that eth0 is connected to the production net. But you do not know which other NIC is connected to the same switch as there are different server generations and/or the network guys use the wrong NICs for their connections.
Task at hand
As this setup is typical for your infrastructure, you want to automate the configuration of bonding interfaces. Now you have the task to detect which NICs are not connected at all and which NICs are linked to the same switch so they may be bonded. You have only access to Linux boxes and cannot query the switches.
Ideas
Detecting the link status is easy:
ethtool $device | grep 'Link detected' | cut -d ':' -f 2
But how to match the devices that are connected to the same switch?
In HP-UX there is a tool for that purpose called linkloop [1]. The official Linux tool is missing (there is an old SourceForce project, though).
Possible solutions that already have come to my mind are:
Listen on all interfaces with tcpdump. Craft and send an ICMP (broadcast) packet. The interfaces that see that packet need to be connected to the same switch. -> need suggestions of simple tools that may be used for that. I would like to use plain shell commands or Python for the scripting.
Try to talk to an external box via some easy protocol (HTTP?) and see if there is a response. -> Error prone and dependent on an external box.
Do you have further ideas or suggestions how to solve this task?
Thank you in advance for all comments!