How to check valid IP Address in C#

sam
sam
Member
378 Points
48 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: 9461
Total Answered: 1
Total Marked As Answer: 0
Posted On: 13-May-2016 23:36

Share:   fb twitter linkedin
Answers
NiceOne Team
NiceOne...
Editor
1382 Points
14 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