How to

check validity of IP address

Published: 22. January 2009 | Updated: 22. January 2009
License: Microsoft Public License (MS-PL)
Categories: Network
Tags: C# Network
Was this snippet helpful for you? YESYES / NONO

Import namespace

using System.Net;

Code

string ipAddress = "10.20.30.40";
IPAddress ipObj = null;

if (IPAddress.TryParse(ipAddress, out ipObj))
{
    Console.WriteLine("IP {0} is valid", ipObj);
}
Send us feedback about this snippet »



Related Snippets: