I store it in a long, very fast for lookup. You can use the following functions for conversion.
public static string GetStandardIP(long numericIP)
{
string w = Convert.ToString(Convert.ToInt64(numericIP / 16777216) % 256);
string x = Convert.ToString(Convert.ToInt64(numericIP / 65536) % 256);
string y = Convert.ToString(Convert.ToInt64(numericIP / 256) % 256);
string z = Convert.ToString(Convert.ToInt64(numericIP) % 256);
return w + "." + x + "." + y + "." + z;
}
And this one
public static long GetNumericIP(string standardIP)
{
if (standardIP != null && standardIP != string.Empty)
{
string[] ipParts = standardIP.Split('.');
long numericIP = 16777216 * Convert.ToInt64(ipParts[0]) + 65536 * Convert.ToInt64(ipParts[1]) + 256 * Convert.ToInt32(ipParts[2]) + Convert.ToInt32(ipParts[3]);
return numericIP;
}
return 0;
}
You may want to improve them by doing checks on the parameters.