A lightweight and easy-to-use class library to allow port forwarding in NAT devices (Network Address Translator) that support Universal Plug and Play (UPNP) and/or Port Mapping Protocol (PMP).
Get Started
| Product | Versions |
|---|---|
| .NET | |
| .NET Standard | |
| Other |
README
SharpOpenNat
SharpOpenNat 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).
Build Status
Goals
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
How to use?
With nuget :
Install-Package SharpOpenNat
Go on the nuget website for more information.
Example
The simplest scenario:
var device = await OpenNat.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.
using var cts = new CancellationTokenSource(10000);
var device = await OpenNat.Discoverer.DiscoverDeviceAsync(PortMapper.Upnp, cts.Token);
await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, 1600, 1700, "The mapping name"));
Documentation
- Why Open.NAT? Here you have ten reasons that make Open.NAT a good candidate for you projects
- Visit the Wiki page
Development
You are welcome to contribute code. You can send code both as a patch or a GitHub pull request.
| Description | Value |
|---|---|
| License | The MIT License (MIT) |
| Documentation | http://jeremyansel.github.io/SharpOpenNat |
| Source code | https://github.com/JeremyAnsel/SharpOpenNat |
| Nuget | https://www.nuget.org/packages/SharpOpenNat |
| Build | https://ci.appveyor.com/project/JeremyAnsel/sharpopennat/branch/main |
Downloads by Version
Similar & Alternative Packages
Hand-picked matching NuGet libraries based on tags & ecosystem
Depended On By
Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.