Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically detect a new computer connected to the network

Tags:

networking

Is there an elegant way to make a program detect a new computer that is connected to the network?

I would like my program to "auto-sense" a new computer being connected on the network (they're on the same network). Like a USB device being connected to the computer.

What I'm doing now is to save a list of all computers in the network from time to time. Another approach is to PING all available IPs on the subnet.

Are there any other elegant approaches?

Thanks!

like image 391
Ian Avatar asked May 20 '10 12:05

Ian


People also ask

How can I detect another computer?

One way to check this is to use the ping command from a PowerShell or command line. This will allow you to see whether your PC is connected to your network correctly and can detect other local network devices, but to do so, you'll need to know the local IP or hostname for another local PC.

How do I find new devices on my network?

The best way to find this information will be to check your router's web interface. Your router hosts your Wi-Fi network, so it has the most accurate data about which devices are connected to it. Most of the best routers offer a way to view a list of connected devices, although some may not.


1 Answers

Listening for ARP requests is the canonical way to do this. Independent of DHCP or not, any connected computer that wishes to communicate with the outside world will have to make an ARP request for the address of the default router. This request will go out as a broadcast, and contain the source interface's MAC and IP adresses.

If the other computer uses DHCP, it will make an ARP request for it's own address as part of duplicate address detection, which is also a broadcast you can snoop on.

(This works more or less the same way for IPv6, except you need to look for neighbor discovery or router soliciation packets instead.)

Like the answer alluded to, if you have a switch to which you can telnet or use SNMP on, you can extract the MAC table. That will give you a list of MAC adresses on each port in the switch. If you want the IP addresses however, you still need to listen for ARP:s.

On the other hand, if you have access to the default gateway on the network, you can also look at the ARP table there. That will give you MAC and IP addresses for anyone that has recently (for different values of recently...) communicated with it.

like image 164
Jakob Borg Avatar answered Sep 28 '22 07:09

Jakob Borg