Basically, it can't be done efficiently.
Most P2P networks rely on seeding information (lists of existing nodes it can try to connect to). I take it from your question that you want to a solution that doesn't require seeding information to be given to the nodes.
Without seeding information, nodes in P2P networks are limited to trying random addresses. This can work successfully if (A) the number of P2P nodes in the network is large and (B) many/most nodes have the ability to accept incoming connections (i.e., are not behind NAT).
For 2 nodes on IPv4, this will mean billions of packets sent before they discover each other, if one of them can accept inbound connections.
If neither can accept inbound connections, they must attempt to connect to each other simultaneously to achieve nat traversal. The chance of success is only about one in 2^64 per attempt. This is since they each have to guess the other's address correctly. This is simply not going to work.
Obviously, everything gets harder with IPv6.