MyBB Community Forums
How are IPs encoded in Database - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: 1.8 Support (https://community.mybb.com/forum-175.html)
+--- Forum: General Support (https://community.mybb.com/forum-176.html)
+--- Thread: How are IPs encoded in Database (/thread-174561.html)



How are IPs encoded in Database - Thomas131 - 2015-08-13

Hello!
How are IP-Adresses encoded in the Database?

My first idea was that they were splited by dots and every part was converted to hex. Sadly my attempt to change a IP for testing if it works failed.

Then I searched the MyBB-Code (just scanned) and found the my_inet_pton()-Function which returned unreadable results. Is this the function? How to get this values to phpmyadmin?

The $db->escape_binary()-Function seems to have no affect on MySql, has it?

Thanks in advance ...
Thomas131


RE: How are IPs encoded in Database - Ad Bakker - 2015-08-13

These are the two ip functions that I can find in /inc/functions.php:

/**
 * Converts a human readable IP address to its packed in_addr representation
 *
 * @param string The IP to convert
 * @return string IP in 32bit or 128bit binary format
 */
function my_inet_pton($ip)


/**
 * Converts a packed internet address to a human readable representation
 *
 * @param string IP in 32bit or 128bit binary format
 * @return string IP in human readable format
 */
function my_inet_ntop($ip)



RE: How are IPs encoded in Database - Thomas131 - 2015-08-13

@Ad Bakker: Thanks, but I already knew that! The one function produces unreadable results and is already mentioned in my first post and the other one should do the opposit.

[english letter ending],
Thomas131


RE: How are IPs encoded in Database - Ad Bakker - 2015-08-13

OK, but when I set "Show Posting IP Addresses" to "all users", the correct IP address is shown at the bottom of posts. So the function my_inet_ntop seems to convert the IP address as stored in the database correctly.


RE: How are IPs encoded in Database - StefanT - 2015-08-13

PHP documentions covers both functions:
http://php.net/inet_pton
http://php.net/inet_ntop


RE: How are IPs encoded in Database - Thomas131 - 2015-08-17

Thanks for answering and sorry, the my_inet_*()-Functions were the key. My fault was that I tried to Copy&Paste binary Codes between phpMyAdmin, Terminal and another phpMyAdmin.

Thanks again for answering!
Thomas131