How to check valid IP Address in C#

sam
sam
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?

Thanks...

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

Share:   fb twitter linkedin
Answers
NiceOne Team
NiceOne...
Admin
408 Points
69 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
banner

Blog

Active User (2)

 Log In to Chat