简体   繁体   中英

get hosts in my LAN listening on a specific port

I am developing a network game in C under Linux, so the users in the LAN can play with each other. Therefore a server is running in each host, listening in a specific port.

So a client must realize a scanning of all the hosts in the same LAN listening the port. I could use nmap, but nmap will yield too much information that I will have to compute with a pipe, isn't it??

Please, let me know if you think the following idea is suitable.

If I knew my own IP address, I would know the type of IP address, AB or C, and also I would know the part of the IP aimed for hosts. So using the socket system call “connect” to the specified port I am able to know all the hosts in my network offering this service.

What do you think is better??

Thank you very much!!!

make a broadcast with your own ip in it and let the others response to you with theirs ip, so simple. you could use avahi (zeroconf) for this.

Use broadcast or multicast-multicast is a special type of broadcasting data only to interested clients. Check it out here: http://www.ibiblio.org/pub/linux/docs/howto/other-formats/html_single/Multicast-HOWTO.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM