Detect local private network addresses in geolocations

Detects IPs from the local network that were previously set as 'Not Found'
https://en.wikipedia.org/wiki/Private_network

Affects issues:
- Close #2658
This commit is contained in:
Aurora Lahtela 2022-12-03 10:24:01 +02:00
parent d2eae82ca8
commit 2cc6a1eb60

View File

@ -131,6 +131,7 @@ public class GeoLite2Geolocator implements Geolocator {
public Optional<String> getCountry(InetAddress inetAddress) { public Optional<String> getCountry(InetAddress inetAddress) {
if (inetAddress == null) return Optional.empty(); if (inetAddress == null) return Optional.empty();
if (inetAddress.getHostAddress().contains("127.0.0.1")) return Optional.of("Local Machine"); if (inetAddress.getHostAddress().contains("127.0.0.1")) return Optional.of("Local Machine");
if (inetAddress.isSiteLocalAddress()) return Optional.of("Local Private Network");
try ( try (
// See https://github.com/maxmind/MaxMind-DB-Reader-java#file-lock-on-windows // See https://github.com/maxmind/MaxMind-DB-Reader-java#file-lock-on-windows