Page 1 of 1

CeratorIP Format

Posted: 2020-12-16 23:26
by SkayyHH
The AppGini function CreatorIP does not give me the correct IP number format. But like this
2003:c0:ff29:ff00:71ba:3b70:d709:7a70

Database is UTF8. I have also tested other formats.

Does anyone have an idea what the problem is?

Thank you, Kai

Re: CeratorIP Format

Posted: 2020-12-17 04:38
by jsetzer
... 2003:c0:ff29:ff00:71ba:3b70:d709:7a70 ...
That IP looks like a normal IP v6 (https://en.wikipedia.org/wiki/IPv6_address). So I guess the function (parseCode in incCommon.php) still works correctly and there is no problem with the code.

You can check your IP in PHP by yourself:

Code: Select all

$ip = $_SERVER['REMOTE_ADDR'];
If someone is interested:
I have written an article in March 2020 about storing the string representation of IP-addresses, both, IP-v4 and IP-v6, in relational databases:
https://appgini.bizzworxx.de/appgini/da ... databases/

Re: CeratorIP Format

Posted: 2020-12-17 07:25
by SkayyHH
Hi Jan, thank you for the answer. I have looked at your page.

Is there a way to store the IP number in a numeric format in the database? So that on the page the field is displayed as e.g. 192.168.0.1 ?

Thanks a lot!

Re: CeratorIP Format

Posted: 2020-12-17 08:10
by jsetzer
Is there a way to store the IP number in a numeric format in the database?
Well, of course you can convert each hexadecimal fragment of an IPv6 address into a numeric (integer) value and store 8 (or more) integers in the database, but this will not make any sense for various reasons.

--
Excerpt from wikipedia:
An IPv6 address is represented as eight groups of four hexadecimal digits, each group representing 16 bits (two octets, a group sometimes also called a hextet[6][7]). The groups are separated by colons (:). An example of an IPv6 address is:

Code: Select all

2001:0db8:85a3:0000:0000:8a2e:0370:7334
--
Obviously, 8 (or more) integers, converted from hex (IPv6), can never be stored in 4 bytes (IPv4) without data loss. It is like putting a trillion big elephants into 4 too small dog-houses.
So that on the page the field is displayed as e.g. 192.168.0.1 ?
No, you cannot convert every possible IPv6 addresses into a 4-byte-IPv4 representation without data loss.

The major reason why IPv6 was invented years ago was that IPv4 range is much too small for all publicly addressable devices in the world today. There may be hacks for looking up matching IPv4 addresses within a Local Area Network but this will probably never work for addresses outside a given subnet.

So, we all have to get used to the fact that an IP address no longer looks like it did in the 1990s ;)

IPv6 is a valid IP address representation. If you want to store the IP-address, just store the IP address :!:

PS: There is no place like 127.0.0.1 :D

Re: CeratorIP Format

Posted: 2020-12-17 10:59
by SkayyHH
Hi Jan,

thank you for the effort to give me such a detailed answer.

I think I'll just leave out the ip in my audit log ;-)

Many greetings, Kai