Open.Nat.V2 is a lightweight and easy-to-use class library to allow port forwarding in NAT devices that support UPNP (Universal Plug & Play) and/or PMP (Port Mapping Protocol).
The parent repository was archived last year, and I forked this to keep it going. I retargeted the Library to .NET Standard 2.0 (which supports .NET Framework 4.6.1 and newer) and removed a lot of the legacy .NET Framework 3.5 baggage. I also updated/reworked the Unit Tests, and the current build is passing all tests =) Enjoy!
NATed computers cannot be reached from outside and this is particularly painful for peer-to-peer or friend-to-friend software. The main goal is to simplify communication amoung computers behind NAT devices that support UPNP and/or PMP providing a clean and easy interface to get the external IP address and map ports and helping you to achieve peer-to-peer communication.
- Tested with .NET YES
- Tested with Mono YES
With nuget :
Install-Package Open.Nat.V2
Go on the nuget website for more information.
The simplest scenario:
var discoverer = new NatDiscoverer();
var device = await discoverer.DiscoverDeviceAsync();
var ip = await device.GetExternalIPAsync();
Console.WriteLine("The external IP Address is: {0} ", ip);The following piece of code shows a common scenario: It starts the discovery process for a NAT-UPNP device and onces discovered it creates a port mapping. If no device is found before ten seconds, it fails with NatDeviceNotFoundException.
var discoverer = new NatDiscoverer();
var cts = new CancellationTokenSource(10000);
var device = await discoverer.DiscoverDeviceAsync(PortMapper.Upnp, cts);
await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, 1600, 1700, "The mapping name"));For more info please check the Wiki
- Why Open.NAT? Here you have ten reasons that make Open.NAT a good candidate for you projects
- Visit the Wiki page
