jvxk-q
Last Updated: February 25, 2016
·
330
· jasonyost
2182167268 72

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;
        }
Say Thanks
Respond