Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
152 views
in Q2A Core by

Hi

How to read the IP address in the DB? like in Columns createip, loginip...

i found this this format "0x2a020ce02800d7ffd..." this is not IPv4 or IPv6!

what type of format is that? and how to convert it to human readable form?

i am using cloudflare, and want to see if the DB logs users IP's or cloudflare's

Ali

Q2A version: https://github.com/pupi1985/question2answer/tree/bugfix-pupi1985

1 Answer

+1 vote
by
selected by
 
Best answer

To get the datatype of a field in a database table use the DESCRIBE statement on that table, e.g.

DESCRIBE qa_users;

(Reference)

The type of IP fields in the Q2A database is varbinary(16) (since IP addresses are basically just integer numbers, even though they're normally displayed in a particular format to make them more readable). To resolve those values to a human-readable IP address use the function inet6_ntoa(), e.g.

SELECT inet6_ntoa(createip) FROM qa_users;

...