Question

I want to find all ip addresses that are connected (in LAN).

I used lookupHost() function explained in this link: lookupHost function description

But my application says “Found address:” for all ip addresses!

I don`t want to use QProccess.

glad to hear your ideas.

Thanks a lot. Ya Ali.

Was it helpful?

Solution

There is no reliable way to determine all hosts in a LAN. 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. e.g you can try to ping a broadcast, but someone could not reply to the ping. So there is no way in Qt or others to do it. There are some ways which rely on commands in a terminal. You can try using nmap. Although it needs to install nmap:

nmap -sP 192.168.1.*

This does a simple ping scan in the entire subnet to see which all host's are online.

Or you can also try the following steps (Does not require installing nmap):

  • Type “ipconfig” at command prompt. This will give you ip address of your own machine. For example, your machine ip address is 192.168.1.6 So your broadcast IP address is 192.168.1.255.
  • Ping your broadcast IP address “ping 192.168.1.255” (may require -b on linux)
  • Now type “arp –a” You will get the list of all IP addresses on your segment.

In Qt you can use QProcess to accomplish them like:

QProcess myProcess;
QString program = "nmap";
QStringList arguments;
arguments << "-sP" << "192.168.1.*";
myProcess.start(program, arguments);
myProcess.waitForFinished();
QByteArray result = myProcess.readAllStandardOutput ();
const QString all(result);

OTHER TIPS

I created a dll to find all online IP addresses and their MAC addresses in the LAN. Share with you:

I wrote an article about this topic and posted in CodeProject:

http://www.codeproject.com/Articles/798730/Finding-All-Online-IP-Addresses-Simple-Method

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top