Skip to main content

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).

Total Downloads
8.5K
8,535
Published
Jul 1, 2026
3mo ago

Get Started

dotnet add package SharpOpenNat --version 4.0.19
ProductVersions
.NET
net6.0net8.0
.NET Standard
netstandard2.0
Other
.NETFramework4.8

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

Build status NuGet Version License

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

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.

No SPDX license expression is published. Review the license text and your organisation's policy before redistribution.Compatibility metadata lists 4 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.