How to check valid IP Address in C#

134 Points
62 Posts

I am try to check a given IP Address is valid or not. I am try to use regex for this. Is there any other way to check IP Address is valid or not?


Views: 8197
Total Answered: 1
Total Marked As Answer: 0
Posted On: 13-May-2016 23:36

Share:   fb twitter linkedin
NiceOne Team
404 Points
67 Posts

Hey Sam,

Yes you can use IPAddress class to check IP address 

public static bool IsValidIPAddress(string IP)
IPAddress ip; 
return IPAddress.TryParse(IP, out ip);

The above static method will return true if valid IP else false. For this you need to use package

using System.Net;
Posted On: 13-May-2016 23:41
 Log In to Chat