0

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 !!

3
  • if its hexadecimal, convert to decimal using echo hexdec('4c44b817'); Commented Feb 28, 2016 at 22:00
  • i already tryed this, but the result is just "13" Commented Feb 28, 2016 at 22:08
  • for me its: 1279571991. What database/table are we talking about? Commented Feb 28, 2016 at 22:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

this is probably what was wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.