December 30, 2011

Berton Berton
Lab Rat
4 posts

How to get all IP address on a LAN ?

 

I have no idea how to get all IP address on a LAN.

10 replies

December 30, 2011

koahnig koahnig
Mad Scientist
2112 posts

Welcome to devnet forum

Probably you may have to elaborate a bit more what you are trying to do.

December 30, 2011

Berton Berton
Lab Rat
4 posts

Sorry, I want to get a list of IP address of all computers connected to a same lan. But I don’t know what method I can use in Qt.

December 30, 2011

koahnig koahnig
Mad Scientist
2112 posts

AFAIK there is no support of Qt for your task. I would assume that you require the support of your LAN access point for providing all IP addresses. For instance a router modem may tell you all IP addresses connected.

December 30, 2011

Berton Berton
Lab Rat
4 posts

thanks. may be i need to find a alternative method to fix it.

December 30, 2011

fluca1978 fluca1978
Ant Farmer
524 posts

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.

January 2, 2012

aureshinite aureshinite
Lab Rat
61 posts

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.

January 2, 2012

fluca1978 fluca1978
Ant Farmer
524 posts
aureshinite wrote:
You can use ARP

Arp will work as a cache, so it is not safe either to query via arp other network cards.

January 2, 2012

aureshinite aureshinite
Lab Rat
61 posts

fluca1978 wrote:

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.

January 2, 2012

Volker Volker
Robot Herder
5428 posts

There is no reliable way to determine all hosts in a LAN. Point.

There are many means of guessing your neighbors, each with its own advantages and drawbacks. But you will never be sure you get all hosts.

January 3, 2012

fluca1978 fluca1978
Ant Farmer
524 posts

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.

 
  ‹‹ Increase the size of the box in a form to fit the text      How to show text cursor in QTextEdit Widget, if the widget doesn’t have focus. ››

You must log in to post a reply. Not a member yet? Register here!