Working with IP addresses in C#

// get the host IP addresses
var hostIPs = System.Net.Dns.GetHostAddresses("LocalHost");

// get the local computer name
var localHostName = System.Net.Dns.GetHostName();

// get the local IP addresses
var localIPs = System.Net.Dns.GetHostAddresses(localHostName);

And here’s the full exam­ple with a method to check whether an IP address is local:

Liked this post? Why not support me on Patreon and help me get rid of the ads!