Daily Lucky Numbers:
2
10
19
37
38
39
Message
Author
Board
Date
January 08, 2025, 11:48:54 PM
January 07, 2025, 10:44:05 PM
January 07, 2025, 02:02:16 AM
January 07, 2025, 01:46:56 AM
January 07, 2025, 01:16:38 AM

IPV4

Started by Duban Black, January 08, 2025, 08:46:44 AM

Previous topic - Next topic

Duban Black

This forum uses some mod to always show ipv4? in most SMF forums the ip is shown in ipv6.

Chen Zhen


There isn't any modification installed to alter the IP address.
It might have something to do with the network my host provides or possibly because I haven't configured something properly.
Thanks for the report, I will look into it.

Duban Black

Yes, it's curious, because in all SMF forums my ip always shows the ipv6 version, but here it shows me the ipv4, which I prefer to see and I wanted to replicate it in my forum.
If you find the necessary setting please let me know.

Chen Zhen

#3
Yes but I don't think it's a real IP address for you.
There is likely some script that generates it from your IPv6 address so it will always show as the same but it's not legit.
Your ISP has assigned you a IPv6 which may be dynamic & assigned when your modem/router powers up & connects to your ISP's network or it may be static & always the same from the day you signed up for your ISP service.
IPv4's ran out in 2019 where some ISP's have a pool of them that they use.

There is a PHP script that can convert IPv6 to IPv4 which will always be the same when using the same IPv6 digits but like I said, it's not really a legit IPv4 address. There is at least a 1 in 4,294,967,296 chance that it will be a duplicate of a legit IPv4 but even higher odds for your site because how many of those IP's are going to visit? I suppose it's not hugely important to be legit because of mainly dynamic use of them by ISP's so you can use a script to change it without any problem. 

Chen Zhen

#4
For example, you can use something like this:

Note: requires PHP 8.2+
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {   
    $ipv4 = hexdec(substr($ip, 0, 2)) . '.' . hexdec(substr($ip, 2, 2)) . '.' . hexdec(substr($ip, 5, 2)) . '.' . hexdec(substr($ip, 7, 2));
    $ip = $ip == '::1' ? '127.0.0.1' : (inet_ntop(inet_pton($ip)) == '::1' ? '127.0.0.1' : (filter_var($ipv4, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? $ipv4 : $ip));       
}
elseif (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
    // invalid IP ~ do not allow login process
    $ip = '';
}
if (!empty($ip) && !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_GLOBAL_RANGE)) {
    // invalid IP range ~ do not allow login process unless using loopback
    $ip = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) ? '' : $ip;
}

Like I said, this is really a bogus IP but it will generate the same corresponding IPv4 address.