Class NetHelper
A static utility class providing network-related helper methods, such as fetching the external IP address and validating loopback addresses. IP address and hostname validation is delegated to the IsAddressValid(string) method.
public static class NetHelper
- Inheritance
-
NetHelper
- Inherited Members
Methods
FetchExternalIPAddress(Action<string>, Action<string>, string)
Asynchronously fetches the external (public) IP address of the client using a specified web service. This method typically relies on a service that simply returns the client's public IP address as plain text.
public static IEnumerator FetchExternalIPAddress(Action<string> onSuccess = null, Action<string> onError = null, string serviceUrl = "https://checkip.amazonaws.com/")
Parameters
onSuccessAction<string>An optional callback action that receives the fetched IP address (string) upon success.
onErrorAction<string>An optional callback action that receives an error message (string) if the request fails or returns an invalid IP.
serviceUrlstringThe URL of the web service to query for the external IP address. Defaults to "https://checkip.amazonaws.com/", which returns a plain text IPv4 address.
Returns
- IEnumerator
An IEnumerator suitable for use with StartCoroutine to run the web request.
IsLoopbackAddress(string)
Returns true if address is a loopback address,
covering 127.0.0.1, ::1, localhost, and all other variants
that IsLoopback(IPAddress) detects.
public static bool IsLoopbackAddress(string address)
Parameters
addressstringThe address string to check.
Returns
- bool
True if the address is a loopback address.