I'm on the lookout for an inexpensive 5-port switch that will allow me to identify the IP address assigned to each port. Ideally, I should be able to access this information via Python or the command line. One suggestion was to use SNMP, but I'm uncertain which switch models would support this feature and if it would work as I need it to.
To provide more context, I have two identical smart devices (let's refer to them as cameras) labeled left and right in a physical test setup. Our software requires us to differentiate which camera is which.
One option would be to physically label the cameras and hard-code their MAC addresses, but we want flexibility for swapping cameras. Another idea is implementing a pairing mode in the software where it asks for the first camera to be plugged in, saves the IP, and then does the same for the second camera. However, this could complicate the user interface and lead to additional edge cases.
Therefore, our preferred solution would be to just plug the left camera into the leftmost port and the right one next to it on the switch.
8 Answers
Switches operate primarily at the MAC layer, so they don’t inherently manage IP addresses. To achieve what you're trying to do, you'll need a Layer 3 switch that can handle IP services for those ports. Alternatively, you might need to query an upstream Layer 3 device to get the MAC address associated with an IP and then figure out which port that MAC is connected to on your switch. But honestly, it sounds like you might be overcomplicating this a bit. Can you clarify your overall goal?
Thanks for the insight! I added more context in the original post's edit.
If you can access the switch via SSH, leveraging the Python library Ansible could really assist you in managing this setup effectively.
It's feasible to do what you're suggesting, but it might not be the best route. You could run into issues as your setup grows. I'd recommend establishing a system where MAC and IP addresses are registered for your devices, especially when new ones come in. This way, your solution doesn't hinge on a specific switch model and allows for scalability.
Using hostnames and DHCP reservations could be a clever way to distinguish between the devices by their IP addresses. This approach would work well if you plan to switch devices often, as long as the devices retain their assigned DHCP reservations.
If you're looking for simplicity, check out arp tables or consider using the Link Layer Discovery Protocol (LLDP). These could help you get the information you need without a lot of hassle.
Most managed switches should be able to help with this, particularly if you're interested in accessing the MAC table. If you're focused specifically on a 5-port model, you might have to look a bit harder, as they often start at 8 ports.
Exactly, you won't get much info above Layer 2 directly from the switch. You would indeed need to get the MAC-to-IP information from another Layer 3 device.
Cisco switches can be set up to assign DHCP based on the port where the request comes in. This means that once set up, your left camera could consistently receive the same IP address every time.
You might also consider configuring each port to a different VLAN and subnet, which would make it easy to identify the devices based on their IP addresses. As long as you have a managed switch that supports multiple VLANs, this could be a solid solution.

Definitely! That’s a good point. You might want to expand on what you’re ultimately trying to achieve.