MySQL IP processing functions inet_aton () and Inet_ntoa ()

Source: Internet
Author: User

Given a "point address" (such as 127.0.0.1) for a network address as a string, returns an integer representing the value of the address. The address can be either a 4 or a 8-bit address.

mysql> SELECT Inet_aton (' 209.207.224.40 ');

3520061480

The resulting numbers always follow the network byte order. As the example above, the numbers are calculated according to 209x2563 + 207x2562 + 224x256 + 40.

Inet_aton () can also understand short format IP addresses:

mysql> SELECT Inet_aton (' 127.0.0.1 '), Inet_aton (' 127.1 ');

--2130706433, 2130706433

Note: When storing values produced by Inet_aton (), it is recommended that you use the INT UNSIGNED column. If you use the (signed) int column, the corresponding first eight-bit group of IP address values greater than 127 will be up to 2147483647 (that is, the value returned by Inet_aton (' 127.255.255.255 ')).

* INET_NTOA (expr)

Given a digital network address (4 or 8 bits), returns the representation of the address as a string.
*
Mysql> SELECT Inet_ntoa (3520061480);

' 209.207.224.40 '

Transferred from: http://www.rocing.cn/?action=show&id=233

MySQL IP processing functions inet_aton () and Inet_ntoa ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.