Working with IP addresses in C#

Presently sponsored by Serverless Guru: Your guide to cloud excellence, helping you every step of your serverless journey, including team training, pattern development, mass service migrations, architecting, and developing new solutions. Speak to a Guru today.
// 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:

http://www.csharp-examples.net/local-ip/

Leave a Comment

Your email address will not be published. Required fields are marked *