Imagine a group of laptop users that are within close proximity. I want an application to constantly seek out users within range and establish a connection with multiple users.

My first strategy was to randomly assign a port to each machine and have a background process constantly scanning all other ports for listening connections. But i didn't think this would work given that every machine would have the same network IP and it would wind up scanning itself.

Another strategy would have been to give each computer a random IP within a certain range. But I know that you can only change the last three digits of a machines ip address, this would also only allow me 255 users on a network, but which is fine but I'd probably run into a large number of connection errors.

This is basically an adhoc network app. How should I approach this?