Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/C++ Linux, How to find neighbors on a network Without Using IP (MAC Only)

Tags:

c++

c

linux

macos

In a small network, say 20 nodes or less, my program, on a test instrument, needs to know "Who is out there?" by MAC not by IP. I will be plugging into random networks and need to be able to do this without having to know any addresses, MAC or otherwise in the network and knowing I can't rely on DHCP. It is completely reasonable that the DHCP server could be down and the nodes have no IP addresses and/or, I can't get one. Truthfully, I don't need IP, our test protocol is MAC layer, not IP.

So, how can I determine my instrument's neighbor's MAC addresses? This sounds a lot like LLDP but backwards, i.e., "who's out there", not "I'm here and I can do this...". I must assume there is no IP assigned to the endpoints, so no ARPing, no NMAP, etc.

Note I should add, this is a wired network.

like image 770
Wes Miller Avatar asked Jan 13 '14 16:01

Wes Miller


People also ask

How do I find the MAC address of a network in Linux?

On a Linux machineOpen a terminal window. Type ifconfig at the command prompt. Your MAC address will be displayed beside the label HWaddr.

What are IP neighbors?

The ip neigh command manipulates neighbour objects that establish bindings between protocol addresses and link layer addresses for hosts sharing the same link. Neighbour entries are organized into tables. The IPv4 neighbour table is also known by another name - the ARP table.


1 Answers

In the general case, there is no MAC level protocol that you can send and guarantee a response from every machine on your network (I am assuming you are using ethernet here as I believe things are different on WLAN). IE there is no broadcast (or even, IIRC unicast) at the MAC layer that a host is guaranteed to respond to. With IP on top, you can IP broadcast and check the ARP cache.

The best way to do this would (in my opinion) be to use the way switches / learning bridges work on ethernet, i.e. passively listen in promiscuous mode for packets and note their MAC addresses. You won't spot completely silent hosts, but neither will a switch until a packet is sent by it. By definition there is no way to spot a completely silent host anyway.

like image 157
abligh Avatar answered Oct 24 '22 14:10

abligh