Scanning ports are a poor choice, most likely you will run firewalls on computers on the network to display your machine as an attacker. Any network intrusion detection system can also be launched. This is a lot of overhead for what you need.
I would recommend doing the broadcast using UDP or multicast to detect other clients http://www.codeproject.com/Articles/1705/IP-Multicasting-in-C
Another option would be to create a centralized server on a web server (php script, asp.net page, etc.) or a web service (REST) ββwith which the chat client will connect at startup, POSTing it listens for IP / Port, and then in turn will receive a list of all recently announced IP / ports of other clients on the network. You probably want someone to stay alive here, IE: the client will send POST to the page every 5 minutes, if the IP address is not POST for 10 minutes, it will be removed from the list.
To get the public IP address of the device, you can check this page: http://www.whatismyip.com/faq/automation.asp
You just need to send a web request to get the IP address. If you want to get the IP address not 0.0.0.0/127.0.0.1 of the local interface, you can check these messages:
Get local IP address
How to get the software IP address of a local area network of a computer? (FROM#)
Developer
source share