Interface INatDevice
Represents a NAT device and provides access to the operation set that allows open (forward) ports, close ports and get the externa (visible) IP address.
Namespace: SharpOpenNat
Assembly: SharpOpenNat.dll
Syntax
public interface INatDevice
Properties
| Edit this page View SourceHostEndPoint
A local endpoint of NAT device.
Declaration
IPEndPoint HostEndPoint { get; }
Property Value
| Type | Description |
|---|---|
| IPEndPoint |
LocalAddress
A local IP address of client.
Declaration
IPAddress LocalAddress { get; }
Property Value
| Type | Description |
|---|---|
| IPAddress |
Methods
| Edit this page View SourceCreatePortMapAsync(Mapping, CancellationToken)
Creates the port map asynchronous.
Declaration
Task CreatePortMapAsync(Mapping mapping, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Mapping | mapping | The Mapping entry. |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
Examples
device.CreatePortMapAsync(new Mapping(Protocol.Tcp, 1700, 1600));
Exceptions
| Type | Condition |
|---|---|
| MappingException | MappingException |
DeletePortMapAsync(Mapping, CancellationToken)
Deletes a mapped port asynchronous.
Declaration
Task DeletePortMapAsync(Mapping mapping, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Mapping | mapping | The Mapping entry. |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
Examples
device.DeletePortMapAsync(new Mapping(Protocol.Tcp, 1700, 1600));
Exceptions
| Type | Condition |
|---|---|
| MappingException | MappingException-class |
GetAllMappingsAsync(CancellationToken)
Gets all mappings asynchronous.
Declaration
Task<Mapping[]> GetAllMappingsAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<Mapping[]> | The list of all forwarded ports |
Examples
var mappings = await device.GetAllMappingsAsync(); foreach(var mapping in mappings) { Console.WriteLine(mapping) }
Exceptions
| Type | Condition |
|---|---|
| MappingException | |
| NotSupportedException | |
| OperationCanceledException |
GetExternalIPAsync(CancellationToken)
Gets the external (visible) IP address asynchronous. This is the NAT device IP address
Declaration
Task<IPAddress?> GetExternalIPAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<IPAddress> | The public IP addrees |
Examples
Console.WriteLine("My public IP is: {0}", await device.GetExternalIPAsync());
Exceptions
| Type | Condition |
|---|---|
| MappingException | MappingException |
GetSpecificMappingAsync(Protocol, int, CancellationToken)
Gets the specified mapping asynchronous.
Declaration
Task<Mapping?> GetSpecificMappingAsync(Protocol protocol, int port, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Protocol | protocol | The protocol. |
| int | port | The port. |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<Mapping> | The matching mapping |
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException |