How to get all IP address on a LAN ?
I have no idea how to get all IP address on a LAN.
10 replies
There is no sure way to achieve it. If computers are in DHCP you have to deal with the DHCP server to get the assigned addresses, but someone could have used a fixed ip address or could have disconnected before the lease expired. You can try to ping a broadcast, but someone could not reply to the ping. The only solution is to rely on a service on each machine announcing to you or that you can poll.
You can use ARP , which is what computers in the same subnetwork use to communicate.
Follow These instructions [windowsitpro.com] to see how it work, but if you want to do it using Qt, you need to create thes packets yourself. Or you can wrap call the script on each OS to get something portable.
Arp will work as a cache, so it is not safe
Can you explain me how it is not safe?
If there is a functioning and trusted (ie it doesn’t send garbage) computer in your LAN, then you can definitely see its address in the ARP cache. The article use ping as a fast way of using it, but ARP itself has multiple way of finding hosts. For example an ARP probe which is usually for testing address conflict can be use. You send it, and you just need to collect hosts details from packets responses. Note that this can also be done from the ping to the broadcast address.
At the length of my knowledge, DHCP is only use between a client and DHCP servers. It cannot obtain information about other clients using DHCP protocol.
The idea is : You need to use broadcast in some way. Either with ping, either with ARP. Not with DHCP.
One thing : a router never retransmit an ARP outside his sub-network. So if your network has an hierarchy of routers, use ping.
A dhcp server knows assigned addresses. The problem is the host could have been disappeared before the lease expires or it could have a static address. In both cases, the dhcp server will not know enough about the client.
An arp discovering is much more complicated than a ping broadcast. None is more sure than the other, since an host can avoid replying a ping or can use arp poisoning.
If you pass a router you are outside your network, so there is no advantage in using ping with respect to arp. Moreover, each time you pass a router you are calling for other troubles, since the router could also filter packets.
As I said in my previous post, and as Volker stated, there is no way to discover hosts on a network. Or better, the only way is to sniff traffic thru a mirrored port over a switch.
You must log in to post a reply. Not a member yet? Register here!



