• Api Documentation
  • Source Code
Search Results for

    Show / Hide Table of Contents
    • SharpOpenNat
      • Extensions
      • INatDevice
      • INatDiscoverer
      • Mapping
      • MappingException
      • MappingLifetime
      • NatDeviceNotFoundException
      • OpenNat
      • PortMapper
      • Protocol

    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 Source

    HostEndPoint

    A local endpoint of NAT device.

    Declaration
    IPEndPoint HostEndPoint { get; }
    Property Value
    Type Description
    IPEndPoint
    | Edit this page View Source

    LocalAddress

    A local IP address of client.

    Declaration
    IPAddress LocalAddress { get; }
    Property Value
    Type Description
    IPAddress

    Methods

    | Edit this page View Source

    CreatePortMapAsync(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

    | Edit this page View Source

    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

    | Edit this page View Source

    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
    | Edit this page View Source

    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

    | Edit this page View Source

    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

    Extension Methods

    Extensions.GetAvailablePortAsync(INatDevice, int, CancellationToken)
    Extensions.GetUsedPortsAsync(INatDevice, CancellationToken)
    • Edit this page
    • View Source
    In this article
    Back to top Copyright Alan McGovern, Ben Motmans, Lucas Ontivero, Jérémy Ansel (c) 2006-2024