Site icon Ryadel

ASP.NET C# Helper Class to get Web Server IP Address and other network-related methods

Classe ASP.NET C# per il controllo e il calcolo formale del Codice Fiscale

Today I want to share this small, yet useful C# helper class that I still use when I need to retrieve, check or validate one or more IP Addresses registered on the Web Server. You can use it for a number of tasks/scenarios, including:

  • Retrieve the first available IP Address of the Web Server machine hosting the Web Application.
  • Retrieve a list of all the IPV4 and IPV6 Addresses registered on the Web Server machine hosting the Web Application.
  • Check if a given IP Address is one of the IP Addresses registered on the Web Server.

The helper class was made some years ago, yet it can still be used on any ASP.NET project, including ASP.NET Forms, ASPX pages, ASP.NET MVC, ASP.NET Web API, ASP.NET WCF with any other framework versions & builds, up to the most recent ASP.NET Core.

Here it is: enjoy!

In case you also need to execute a ICMPv4 PING to a remote host, you can integrate within this class the PingHost method described in this other post.

 

Exit mobile version