0

in previous question i try to get all valid ip addresses in a subnet , so i use for loop , but after i try it , i find that my code takes more that 2 minutes to find an all ip addresses in a sub net , and in some cases it's take more than 5 minutes!

My code is writing in C++ under Mac OS ;

but in windows , to do the same thing you only write net view/all command , and it print all ip addresses in a subnet in a moment !

and in MAC os you can use Bonjour service to do such job .

how these techniques work like this speed (Net view /all and Bonjour service ) ? is there any way to do this job very fast like this ? if not please tell me if is it there is APi to use Bonjour service directly into my code (C++) in mac os?

EDIT:

i found new idea

i found on apple develop some api called Bonjour API , my be it's help ,but how i can use it i c++ , because i know that mac use opbjectiv-c .

bonjour

Community
  • 1
  • 1
user1344201
  • 217
  • 1
  • 5
  • 13

2 Answers2

2

net view /all is working on Windows networking level, not on IP level. It will only list machines with Windows networking and name resolution enabled. If you have computers that are not running Windows (or samba) they won't be listed. The same with printers, routers etc.

With IPv4 the best way is to extract the list of IP addresses in the current subnet by examining the IP address and netmask of your computer. Then force an ARP lookup to be done of each IP address. The ARP lookup will always work if the unit is present on the network, even if it is completely locked down (no ports open, not answering to ping).

With IPv6 you are essentially out of luck. The number of available IP addresses in a single subnet (18 446 744 073 709 551 616) is so wast that an exhaustive search is impossible.

Anders Abel
  • 67,989
  • 17
  • 150
  • 217
  • Bonjour is the Mac equivalent of Windows networking/Samba. It will only detect devices with Bonjour activated (typically Mac computers). It won't get all valid (in use) IPs. – Anders Abel Sep 01 '12 at 11:05
1

You should work asynchronously. You need a function that issues a communication request but returns immediately like IcmpSendEcho2. You will have to create an array of completion events for each call. Each event handle is passed to one IcmpSendEcho2 call.

After that you call WaitForMultipleObjects waiting for ALL events set.

harper
  • 13,345
  • 8
  • 56
  • 105