[SOLVED] How to obtain the list of computers that are in the local network?
I need to create a QTreeView to be able to select a file/directory that can be on the local computer, or in another computer of the local network. I know how to access the data that are on the local computer (QFileSystemModel or a derivative). By I do not find a way to access data that are on another computer of the local network.
I cannot use the QFileDialog::getXXX functions as I need to integrate this explorer in a Dialog window that should show additional elements (content of the file/directory that is quite complex).
Unfortunately I also cannot force the user to map the remote directory. So, this need that I MUST HAVE TO obtain the list of computers names that are present in the local network. And them to access to the public directories that are on each computer. And, to simplify the problem (;-)), I have no information on this local network.
Thanks for your help.
Do you have a Windows Network? If yes NetBIOS is your friend.
Otherwise a simple sniffer program with ping each address.
When you got the list of ip addresses you could accees the remote computer via samba share or ssl?
The software will work on different OS. It is why I am using QT. And I have no information about the network. This mean that I do not have its IP mask.
But you need information about the network. Without ip and netmask you do not have a change to locate the computers.
When you start your program you will know your ip address and netmask, doesn't matter if its static or dynamic assigned. With that you can scan your network. Now it depends if you have Router/Bridges in your network as well.
If you have router/bridges in you network it will be trickier.
Try to solve your problems in the following order
1.) Find all computers in the network. Possible solution: ping all addresses of your subnet
2.) Try to access a specified folder which is accessible from your program. Don't do it the Windows-Way. Use samba/CIFS or webDAV with authentication
3.) Now you can use QDir, QFile and QFileInfo to view the file information of the shared folder.
The problem is that the code will be integrated in a distributed software. It is why I have written that I know nothing about the network. Even, this network may not exist (stand-alone computer). So, what I need is to do something equivalent to "Network" that we find on Windows Platforms. And this is I do not know to do with QT.
The "Network" is based on NetBIOS which is a windows only feature. You can work with it when you use samba. Maybe you can resolve this task with "nmap":http://nmap.org/.
nmap should work under windows, linux and Mac.
tobias.hunger last edited by
In general there is no reliable way to find all hosts on an IP network. ping, nmap, etc. all should get most hosts, but not necessarily all of them and produce a lot of packets to generate their list. This list will then contain all (discovered) hosts on your network, which is usually not what you want: Generally you only care about the hosts that actually offer some service, and not about smart phones that happen to hang in your wlan.
You might want to look into mDNS, bonjour, avahi (different names for the same thing), which allows hosts to advertise their services on the local network and other hosts to discover them.
Tobias is right.
But this means that the customers who bought your software must install or enable the mDNS software/service previously.
What I want is exactly this: discover a set of hosts. Discovering also smartphones that are connected to the network is not a problem. Because I do not need to obtain services from the hosts. I just need to be able to read folders. But I cannot expect that the network be configured using a tool like mDNS. Moreover our software is not for computer specialists. Hence the networks will probably have a "basic (automatic) configuration".
In that case I would do it the other way around.
Every computer which has a public folder has to register to the server with your software.
The network administrator as to send e.g. an email to all users how are responsible to the computer in the network to register to this service. Then you can run your software.
The other way around that the server searches trough a unknown network is very complex because there are so many possibilities that a testing of your software is impossible.
I am just pretty sure that, if customers have to make something so that their computer being seen by my software, they will not do it. In this case it is more simple to force the user of the software to map remote folder to have access to them, or to list them manually.
So, for the first version, as it seems that QT cannot answer to my problem, I think that I will use Windows functions. This means that my software will only be able to work on Windows OS or equivalent (virtual machines on Mac). This limitation might be OK for the initial version of the software. And for the next versions I will have to investigate more about other solutions.
Hi Alain, your problem is not a Qt problem.* It is a network problem.*
I'm not quite sure but even when you are concentrating on Windows platforms it will not automatically solve your problem. Your customer would need a WINS/NetBIOS server installed to find all computers in the unknown network of your customers. And that is definitely not guaranteed.
Yes it si a "network problem". But, as QT has a network module I expected to be able to find a solution using it. For the presence of NetBIOS server, if a standard Windows explorer (when application runs on Windows OS) cannot see the remote computers, my application does not have to see them.
For my software I just need to offer, using a QTreeView, a similar view of what is it seen using QFileDialog::getExistingDirectories. Hence, if a computer needs to be "mounted" to be seen (UNIX case) I just need to show monted computers. And if it needs a NetBIOS server to be seen, I just need to show computers known by this server.
Not correctly. First you have to understand the possibilities how to detect computers in a network for each OS. You have to know the advantages and disadvantages of each solution. Create a document and a solution/choose matrix. Then create a realization plan and try to realize a first solution e.g. discovery method for Windows.
If your software is important for your customers you can also add some install requirements e.g. mDNS
And so on.
tobias.hunger last edited by
"Reading a folder" is done by a service running on a host, so you are interested in service discovery.
Assuming that you are interested in folders shared by windows machines you could read up on the protocols involved... or just use the windows APIs for discovering them directly (assuming you do not care for non-windows platforms running your application).
OK. Finally I do not use QT. I directly use Windows functions. This will be a limitation for the application. But a test on a Mac with parallel desktop shown that these functions also work on Mac.
danil_mark last edited by
[quote author="Alain38" date="1370416822"]OK. Finally I do not use QT. I directly use Windows functions. This will be a limitation for the application. But a test on a Mac with parallel desktop shown that these functions also work on Mac.[/quote]
Excuse me, could you say what exactly you've used?