Is this how I would ping?

Started by
3 comments, last by gamerking 18 years, 7 months ago
hey all, I've just been reading up on what you do to ping but i'm not sure if i have the right idea about going about finding other computers on a network and getting their addresses by ping-ing. my thought: send a small message (say "PING") out to every address on the network (so like "192.056.0.xxx" and go through all 1000 numbers for "xxx"). now this is how i understand ping-ing but wouldnt this take a while to complete? i haven't implemented it yet (since that won't be too hard now that i have my send/receive setup) so i just wanted to see if this is a correct way of ping-ing so i dont freeze my computers or something while trying to do it if it is wrong. also, if it is wrong, please explain how i should go about finding computers to connect to on a network for me. thanks for any info. ps. sorry if this is kinda noob. im new to the whole network programming scene [wink]
the_moo
Advertisement
Don't worry, there's a much easier way. :-)

Instead of sending a ping to all 255 (not 1000) addresses on your local network, simply send ping to 255.255.255.255. This is a special "broadcast" address you can use to send messages to ALL computers on a local network. Any computer on your LAN listening for such a ping will recieve it.
What you probably really want to do is find out the broadcast address for the network you're on, set the socket so that it will send on the broadcast address (using setsockopt() and SO_BROADCAST), and send your message out on the broadcast address that way you only have to send out one message... all of the computers should reply to that one message.

Also the max value for any part of an IP address is 255, not 999.
awesome!
thanks for that you two.
and thanks for the very quick replies too.

also, i did know the max was 255... had a mental blank [wink].
thanks again,
the_moo
hi could i use this to send privite messages to each other on a network if i know the other person's ip and what will i need to do for it to work?
Matt : mattb0001@hotmail.comClick me please

This topic is closed to new replies.

Advertisement