STUN client for address lookups

STUN is a protocol that can be used to lookup a peer’s external address. It also provides information on port mappings and some servers with multiple addresses support the optional feature of receiving connections back from another address. Consequently, such servers allow one to determine the type of NAT you’re behind (if any.)

There are many public STUN servers that can be used for basic functionality. But very few support TCP, IPv6, or multiple addresses, and the ones that do are very unreliable and often experience downtime. P2PD uses STUN heavily to determine the routes that belong to interfaces and their NAT information. The only way to ensure the software worked reliability was to run a STUN server with multiple IPv4/6s on TCP and UDP.

Here is how to use the STUN client.

from p2pd import *

async def example():
    i = await Interface().start()
    nat = await i.load_nat()
    # Test echo server with AF.
    stun_client = STUNClient(i, i.supported()[0])
    wan_ip = await stun_client.get_wan_ip()
    results = await stun_client.get_mapping(TCP)

if __name__ == '__main__':