Open.NAT 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).
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
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
Open.NAT is been developed by Lucas Ontivero (@lontivero). You are welcome to contribute code. You can send code both as a patch or a GitHub pull request.
Here you can see what are the next features to implement. Take it a look! Build Status
-
Allows the creation of mappings with arbitrary Private IP address.
-
Fixes defect #22. Routers failed with 404 when service control url had a question mark (?) - DD-WRT Linux base router (and others probably) fails with 402-InvalidArgument when index is out of range. - Some routers retuns invalid mapping entries with empty internal client.
-
Fixes defect #24. GetSpecificMappingEntry fails with 402-InvalidArgument in DD-WRT Linux base router when mapping is not found.
Fixes defect #20. Absolute service control URL path and query miscalculated.
- Fixes defect #16
- Thus version breaks backward compatibility with v1.
- Changes the event-based nature of discovery to an asynchronous one.
- Managed port mapping timelife.
- Fix for SSDP Location header.
- After this version Open.NAT breaks backward compatibility.
- Minor changes previous to v2.
- Discovery timeout raises an event.
- Permanent mappings are created when NAT only supports that kind of mappings.
- Protocol to use in discovery process can be specified.
- Automatic renew port mappings before expiration.
- Add operations timeout after 4 seconds.
- Add parameters validation in Mapping class.
- Fix UnhandledException event was never raised.
- Discovery timeout added.
- Auto release ports opened in the session.
- Fix NextSearch to use UtcNow (also performance)
- Fix LocalIP property after add a port.
- Tracing improvements
- Discovery performance and bandwidth improved
- Tracing improved
- Cleaner code
##Help me to maitain Open.NAT
15fdF4xeZBZMqj8ybrrW7L392gZbx4sCXH