C# convert IPv4 address to INET_ATON
// Converts the Internet host address cp from the IPv4 numbers-and-dots notation into binary form (in network byte order) and stores it in the structure that inp points to. Returns nonzero if the address is valid, zero if not
public static double INET_ATON(string ipAddress)
{
int i;
double netaddress = 0;
if (ipAddress.ToString() == "")
{
return 0;
}
string[] dec = ipAddress.ToString().Split('.');
for (i = dec.Length - 1; i >= 0; i--)
{
netaddress += ((int.Parse(dec[i]) % 256) * Math.Pow(256, (3 - i)));
}
return netaddress;
}
Written by Jason Yost
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#C#
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#