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

前端 未结 1 1309
醉酒成梦
醉酒成梦 2021-02-20 06:48

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

1条回答
  •  臣服心动
    2021-02-20 07:14

    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.

    0 讨论(0)
提交回复
热议问题