GeoIP: ignore local addresses

This commit is contained in:
Gabriele C
2017-07-07 20:41:10 +02:00
parent 001e5d0376
commit cd4693eedf
3 changed files with 53 additions and 2 deletions
@@ -0,0 +1,28 @@
package fr.xephi.authme.util;
import java.util.regex.Pattern;
/**
* Utility class about the InternetProtocol
*/
public class InternetProtocolUtils {
private final static Pattern LOCAL_ADDRESS_PATTERN =
Pattern.compile("(^127\\.)|(^(0)?10\\.)|(^172\\.(0)?1[6-9]\\.)|(^172\\.(0)?2[0-9]\\.)" +
"|(^172\\.(0)?3[0-1]\\.)|(^169\\.254\\.)|(^192\\.168\\.)");
// Utility class
private InternetProtocolUtils() {
}
/**
* Checks if the specified address is a private or loopback address
*
* @param address address to check
*
* @return true if the address is a local or loopback address, false otherwise
*/
public static boolean isLocalAddress(String address) {
return LOCAL_ADDRESS_PATTERN.matcher(address).find();
}
}