Skip to content

LocalIP

Nill edited this page Oct 26, 2021 · 1 revision

Introduction

The LocalIP class provides a mechanism for determining the local IP address of the machine Telefrag is running on. This is needed when determining the URL or IP address to send to Telegram for setting up Webhooks.

There are a number of mechanisms for Telefrag to determine a local IP:

Method Description
None No IP is determined and the Telegram will use the hostname in the Webhook Base URL to resolve the IP address of your server
DNS Telefrag resolves the machine's local hostname to one or more IP addresses using local reverse DNS
SourceTest Telefrag uses an arbitrary UDP datagram to determine which IP address the operating system automatically assigns as the source address of the socket
ServerFeature Telefrag attempts to resolve an IServerAddressesFeature using ASP.NET dependency injection, which -- if supported -- communicates the server's configured listening addresses
ExternalService Uses an external service such as checkip.dyndns.org to determine the address actually facing the internet
Default Combines the SourceTest, ServerFeature, and ExternalService methods.

If Telefrag is running behind a NAT, ExternalService will most likely be the only method that returns an IP address that is not private.

Obtaining the Local IP

// Getting all local IPs via all methods
var myIps = LocalIP.GetLocalIPs(LocalIPSources.All, false);

// Getting only public IPs using default methods
var publicIps = LocalIP.GetLocalIPs(LocalIPSources.Default, true);

Extensions

Telefrag also adds the IsPrivate() and IsLoopback() extension methods to all IPAddress objects.

Clone this wiki locally