Show / Hide Table of Contents

Class NetUtils

Some specific network utilities

Inheritance
object
NetUtils
Namespace: LiteNetLib
Assembly: LiteNetLib.dll
Syntax
public static class NetUtils

Methods

GetLocalIp(LocalAddrType)

Get first detected local ip address

Declaration
public static string GetLocalIp(LocalAddrType addrType)
Parameters
Type Name Description
LocalAddrType addrType

type of address (IPv4, IPv6 or both)

Returns
Type Description
string

IP address if available. Else - string.Empty

GetLocalIpList(LocalAddrType)

Get all local ip addresses

Declaration
public static List<string> GetLocalIpList(LocalAddrType addrType)
Parameters
Type Name Description
LocalAddrType addrType

type of address (IPv4, IPv6 or both)

Returns
Type Description
List<string>

List with all local ip addresses

GetLocalIpList(IList<string>, LocalAddrType)

Get all local ip addresses (non alloc version)

Declaration
public static void GetLocalIpList(IList<string> targetList, LocalAddrType addrType)
Parameters
Type Name Description
IList<string> targetList

result list

LocalAddrType addrType

type of address (IPv4, IPv6 or both)

MakeEndPoint(string, int)

Creates an IPEndPoint from a host string and a port.

Declaration
public static IPEndPoint MakeEndPoint(string hostStr, int port)
Parameters
Type Name Description
string hostStr

The host name or IP address string to resolve.

int port

The port number for the endpoint.

Returns
Type Description
IPEndPoint

A new IPEndPoint instance.

ResolveAddress(string)

Resolves a host string into an IPAddress.

Declaration
public static IPAddress ResolveAddress(string hostStr)
Parameters
Type Name Description
string hostStr

The host name or IP address string (e.g., "127.0.0.1", "localhost", or "google.com").

Returns
Type Description
IPAddress

The resolved IPAddress.

Remarks

This method handles "localhost" specifically, attempts to parse the string as a direct IP, and falls back to DNS resolution. It prioritizes IPv6 if IPv6Support is enabled.

Exceptions
Type Condition
ArgumentException

Thrown when the address cannot be resolved or is invalid.

ResolveAddress(string, AddressFamily)

Resolves a host string using DNS for a specific AddressFamily.

Declaration
public static IPAddress ResolveAddress(string hostStr, AddressFamily addressFamily)
Parameters
Type Name Description
string hostStr

The host name to resolve via DNS.

AddressFamily addressFamily

The preferred address family (e.g., InterNetwork or InterNetworkV6).

Returns
Type Description
IPAddress

The first IPAddress matching the family, or null if no match is found.

In this article
Back to top Generated by DocFX