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 example with a method to check whether an IP address is local:

Subscribe to my newsletter and get new contents delivered straight to your inbox :-)