Unosquare
    Show / Hide Table of Contents

    Class Network

    Provides miscellaneous network utilities such as a Public IP finder, a DNS client to query DNS records of any kind, and an NTP client.

    Inheritance
    Object
    Network
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Swan.Net
    Syntax
    public static class Network

    Fields

    DnsDefaultPort

    The DNS default port.

    Declaration
    public const int DnsDefaultPort = 53
    Field Value
    Type Description
    Int32

    NtpDefaultPort

    The NTP default port.

    Declaration
    public const int NtpDefaultPort = 123
    Field Value
    Type Description
    Int32

    Properties

    DomainName

    Gets the name of the network domain.

    Declaration
    public static string DomainName { get; }
    Property Value
    Type Description
    String

    The name of the network domain.

    HostName

    Gets the name of the host.

    Declaration
    public static string HostName { get; }
    Property Value
    Type Description
    String

    The name of the host.

    Methods

    GetDnsHostEntryAsync(String)

    Gets the DNS host entry (a list of IP addresses) for the domain name.

    Declaration
    public static Task<IPAddress[]> GetDnsHostEntryAsync(string fqdn)
    Parameters
    Type Name Description
    String fqdn

    The FQDN.

    Returns
    Type Description
    Task<IPAddress[]>

    An array of local ip addresses of the result produced by this task.

    GetDnsHostEntryAsync(String, IPAddress, Int32)

    Gets the DNS host entry (a list of IP addresses) for the domain name.

    Declaration
    public static Task<IPAddress[]> GetDnsHostEntryAsync(string fqdn, IPAddress dnsServer, int port)
    Parameters
    Type Name Description
    String fqdn

    The FQDN.

    IPAddress dnsServer

    The DNS server.

    Int32 port

    The port.

    Returns
    Type Description
    Task<IPAddress[]>

    An array of local ip addresses of the result produced by this task.

    Exceptions
    Type Condition
    ArgumentNullException

    fqdn.

    GetDnsPointerEntryAsync(IPAddress)

    Gets the reverse lookup FQDN of the given IP Address.

    Declaration
    public static Task<string> GetDnsPointerEntryAsync(IPAddress query)
    Parameters
    Type Name Description
    IPAddress query

    The query.

    Returns
    Type Description
    Task<String>

    A String that represents the current object.

    GetDnsPointerEntryAsync(IPAddress, IPAddress, Int32)

    Gets the reverse lookup FQDN of the given IP Address.

    Declaration
    public static Task<string> GetDnsPointerEntryAsync(IPAddress query, IPAddress dnsServer, int port)
    Parameters
    Type Name Description
    IPAddress query

    The query.

    IPAddress dnsServer

    The DNS server.

    Int32 port

    The port.

    Returns
    Type Description
    Task<String>

    A String that represents the current object.

    GetIPv4Addresses(NetworkInterfaceType, Boolean, Boolean)

    Retrieves the local ip addresses.

    Declaration
    public static IPAddress[] GetIPv4Addresses(NetworkInterfaceType interfaceType, bool skipTypeFilter = false, bool includeLoopback = false)
    Parameters
    Type Name Description
    NetworkInterfaceType interfaceType

    Type of the interface.

    Boolean skipTypeFilter

    if set to true [skip type filter].

    Boolean includeLoopback

    if set to true [include loopback].

    Returns
    Type Description
    IPAddress[]

    An array of local ip addresses.

    GetIPv4Addresses(Boolean)

    Retrieves the local ip addresses.

    Declaration
    public static IPAddress[] GetIPv4Addresses(bool includeLoopback = true)
    Parameters
    Type Name Description
    Boolean includeLoopback

    if set to true [include loopback].

    Returns
    Type Description
    IPAddress[]

    An array of local ip addresses.

    GetIPv4DnsServers()

    Gets the configured IPv4 DNS servers for the active network interfaces.

    Declaration
    public static IPAddress[] GetIPv4DnsServers()
    Returns
    Type Description
    IPAddress[]

    A collection of NetworkInterface/IPInterfaceProperties pairs that represents the active IPv4 interfaces.

    GetIPv4Interfaces()

    Gets the active IPv4 interfaces. Only those interfaces with a valid unicast address and a valid gateway will be returned in the collection.

    Declaration
    public static Dictionary<NetworkInterface, IPInterfaceProperties> GetIPv4Interfaces()
    Returns
    Type Description
    Dictionary<NetworkInterface, IPInterfaceProperties>

    A collection of NetworkInterface/IPInterfaceProperties pairs that represents the active IPv4 interfaces.

    GetNetworkTimeUtcAsync(IPAddress, Int32)

    Gets the UTC time by querying from an NTP server.

    Declaration
    public static Task<DateTime> GetNetworkTimeUtcAsync(IPAddress ntpServerAddress, int port = 123)
    Parameters
    Type Name Description
    IPAddress ntpServerAddress

    The NTP server address.

    Int32 port

    The port.

    Returns
    Type Description
    Task<DateTime>

    The UTC time by querying from an NTP server of the result produced by this Task.

    GetNetworkTimeUtcAsync(String, Int32)

    Gets the UTC time by querying from an NTP server.

    Declaration
    public static Task<DateTime> GetNetworkTimeUtcAsync(string ntpServerName = "pool.ntp.org", int port = 123)
    Parameters
    Type Name Description
    String ntpServerName

    The NTP server, by default pool.ntp.org.

    Int32 port

    The port, by default NTP 123.

    Returns
    Type Description
    Task<DateTime>

    The UTC time by querying from an NTP server of the result produced by this Task.

    GetPublicIPAddressAsync(CancellationToken)

    Gets the public IP address using ipify.org.

    Declaration
    public static Task<IPAddress> GetPublicIPAddressAsync(CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    The cancellation token.

    Returns
    Type Description
    Task<IPAddress>

    A public IP address of the result produced by this Task.

    QueryDnsAsync(String, DnsRecordType)

    Queries the DNS server for the specified record type.

    Declaration
    public static Task<DnsQueryResult> QueryDnsAsync(string query, DnsRecordType recordType)
    Parameters
    Type Name Description
    String query

    The query.

    DnsRecordType recordType

    Type of the record.

    Returns
    Type Description
    Task<DnsQueryResult>

    Queries the DNS server for the specified record type of the result produced by this Task.

    QueryDnsAsync(String, DnsRecordType, IPAddress, Int32)

    Queries the DNS server for the specified record type.

    Declaration
    public static Task<DnsQueryResult> QueryDnsAsync(string query, DnsRecordType recordType, IPAddress dnsServer, int port)
    Parameters
    Type Name Description
    String query

    The query.

    DnsRecordType recordType

    Type of the record.

    IPAddress dnsServer

    The DNS server.

    Int32 port

    The port.

    Returns
    Type Description
    Task<DnsQueryResult>

    Queries the DNS server for the specified record type of the result produced by this Task.

    Comments

    Back to top Copyright © 2017-2019 Unosquare