This blog demnostrates how to validate an ip address without doing much of code and without using regex, here i have taken help of System.Net namespace and IPAddress class. The TryParse function of IPAddress determines whether an IP Address is a validate IP Address or not. See the below demonstrator that helps validating IPAddress.
- static void Main()
- {
- IPAddress ip;
- Console.WriteLine("Enter IP Address");
- string ipaddress = Console.ReadLine();
- bool ValidateIP = IPAddress.TryParse(ipaddress, out ip);
- if (ValidateIP)
- Console.WriteLine("This is a valide ip address");
- else
- Console.WriteLine("This is not a valide ip address");
- }