user5448454
user5448454

Reputation:

php decode binary(16) ip from mysql

i have ip's stored in mysql in binary(16) format

in phpmyadmin, it looks like this:

4c44b817

how can i convert it to readable ip string ?

Thanks !!

Upvotes: 0

Views: 396

Answers (1)

lafor
lafor

Reputation: 12776

MySQL has INET_NTOA() function that converts numeric IPv4 address representations to the dotted-quad strings, e.g.:

mysql> SELECT INET_NTOA(0x4c44b817);
+-----------------------+
| INET_NTOA(0x4c44b817) |
+-----------------------+
| 76.68.184.23          |
+-----------------------+

There's also INET_ATON() that works the other way around, as well as INET6_* versions of both functions that work with IPv6 addresses.

Upvotes: 1

Related Questions