Daily Lucky Numbers:
12
20
23
30
37
39

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.

Duban Black

In which template should I register this code?

I usually prefer ipv4 because it is easier and more visible to recognize from the list of ip's I ban, just for practicality and convenience.

Chen Zhen


I don't think you should mess with SMF behavior & what's recorded in the database for IP's.
If it's just because you want it to display the IPv4 visually in your forum then perhaps just filter what's displayed.


Which part of the forum is displaying the IPv6 & you would rather see IPv4?
Is it just the who's online list?


Duban Black

yes, just the ip shown below the profile in the post area, for example this


Duban Black

I just realized that I never uploaded the image, here it is


Chen Zhen


Install the attached mod & set it to JavaScript mode.
If you find that mode to work then leave it set but if it fails then try PHP mode.

Navigate to this mod's settings from:
Admin -> Modification Settings -> Force IPv4 View

Duban Black

ok, I had no problems with the installation.

However when I select javascript I get this error:



When I select php I get this error:



In any case it does not allow me to see the post information.

Chen Zhen

#11
I used a global constant that only exists in PHP 8.2.27 or newer.
The attachment has a fix for your lower version of PHP.




Also note my reason for the PHP vs. JavaScript option...

I wanted to make the mod all hooks, negating the parsing of any SMF template files.
Due to the way SMF stores the IP in the $context array, the PHP option for this mod will render the IP tracking link invalid.
This can be dealt with using a single file edit to theme file(s) if necessary.

The JavaScript option will only change what is visible & will not effect the IP tracking link.
However, I can't be certain this will work for all themes due to the possible use of unique CSS classes (DOM identifiers/manipulation).

Duban Black

#12
The installation works perfectly.

Yes, I think the javascript version is the best, because it is an aesthetic problem, I think it is good that internally the tracking works with the original data.

Visually now you can see the IP with IPV4 format, but I think there is an error with the conversion, because it shows me different data. I leave evidence:
2806:268:488:853:297d:d16:20de:feb

This is the generated IP
40.6.38.8

About the last thing you mention, I checked the browser inspector shows me this:
uBOL: Generic cosmetic filtering stopped because no more DOM changes  css-generic.js:231
I understand that it is just an output generated by the code and does not mean any error, I wanted to mention it anyway.

Thank you very much, you are the best

Chen Zhen


Why are you bothering to run VPN tests on the bogus generated IPv4 addresses?
They're just what is visible for Admins on your forum & are not recorded in the database.
Also your regular users usually can't view any IP's except their own & I doubt they're going to run a check on what's visible.

To be honest, the IPv6 address likely doesn't bother people as this seems to be a pet peeve of yours.

Quote from: Duban Black on March 11, 2025, 08:49:52 PMuBOL: Generic cosmetic filtering stopped because no more DOM changes  css-generic.js:231
This appears to be a misdemeanor message from an add-on that you've loaded into your browser that you can ignore.


Duban Black

In my forum it is forbidden to use VPN and my moderators verify the IPs so that they do not create accounts pretending to be other people.

What I needed was not to create a fake ipv4, but that the ipv6 is transformed into ipv4, but that the IP information itself is the same, I need an equivalent.