List all available LAN IP's using subnet mask
Blitz3D Forums/Blitz3D Programming/List all available LAN IP's using subnet mask
| ||
hi! i was starting a new thread to this one: http://blitzbasic.com/Community/posts.php?topic=75765 because i think, i have chosen the wrong topic title... i was thinking of getting the subnet mask (255.255.255.0 on my machine) and just pinging all 256 possible ips. then i can have a list of all computer which are hanging arround in the network. my problem now is: how do i get the subnet mask? and does it take very long to ping 256 ip's or eventually 65536 ip's? thank you for upcoming answers :) |
| ||
Look at http://www.blitzmax.com/codearcs/codearcs.php?code=1988 |
| ||
this returns 255.255.255.255 to me... and the other problem is: how do i ping a local ip address? |
| ||
I don't think you should talk about pinging the IP since that could turn too complicated to implement. Simple way: If you run a client app and try to find a server, you just attempt your normal handshake with all IP's in the subnet. The one that answers is of course the correct one. I believe that this works only with UDP. Attempting connections with IP's that don't exist using TCP would result in a lot of waiting since all of the incorrect ones need to timeout. |
| ||
Ping to all hosts on a subnet is not a good solution since most systems block ICMP traffic. But they respond at least with an ARP reply. And ARP replies generate entries in the local ARP table which can be looked up simply by 'arp -a' on a windows system. So theoreticaly you can try to read the ARP table from the iphlpapi.dll. I think there is a function called 'GetIpNetTable'. It provides a list of IP - MAC address pairs. best rgds |
| ||
and how do i do that practically? |
| ||
As i said. You can use the iphlpapi.dll to get the arp entires ... create a *.decls file with functions ... this api delivers many other useful network functions from windows. or something like this: Graphics 800,600 ExecFile "ping -n 1 192.168.1.255" Delay 5000 ExecFile "cmd /K arp -a" ; or ExecFile "cmd /K arp -a > arpfile.txt" ; then read the file I would prefer the api. |