add gateway information to IPv6Trick

This commit is contained in:
Peter Hormanns 2023-03-06 11:54:44 +01:00
parent 416e5a9101
commit 5c2f773269
3 changed files with 45 additions and 1 deletions

4
util/.gitignore vendored
View File

@ -1,3 +1,7 @@
/build /build
/target /target
/bin /bin
.classpath
.project
.settings/

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>de.hsadmin.core</groupId> <groupId>de.hsadmin.core</groupId>
<artifactId>hsadmin-util</artifactId> <artifactId>hsadmin-util</artifactId>
<version>4.0.4-SNAPSHOT</version> <version>4.0.5</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>

View File

@ -44,6 +44,46 @@ public class IPv6Trick {
throw new HSAdminException("unknown IPv4 address given"); throw new HSAdminException("unknown IPv4 address given");
} }
public static String IPv4Gateway (final String ipv4address) throws HSAdminException {
if (ipv4address == null || ipv4address.length() == 0) {
throw new HSAdminException("no IPv4 address given");
}
try {
final InetAddress inetV4Address = InetAddress.getByName(ipv4address);
final String inetV4AddressString = inetV4Address.getHostAddress();
if (inetV4AddressString.startsWith(IPv4_83_223_78)) return IPv4_83_223_78 + ".1";
if (inetV4AddressString.startsWith(IPv4_83_223_79)) return IPv4_83_223_79 + ".1";
if (inetV4AddressString.startsWith(IPv4_83_223_91)) return IPv4_83_223_91 + ".1";
if (inetV4AddressString.startsWith(IPv4_83_223_94)) return IPv4_83_223_94 + ".1";
if (inetV4AddressString.startsWith(IPv4_83_223_95)) return IPv4_83_223_95 + ".1";
throw new HSAdminException("unknown IPv4 address given");
} catch (UnknownHostException e) {
throw new HSAdminException(e);
}
}
public static String IPv6Gateway (final String ipv4address) throws HSAdminException {
if (ipv4address == null || ipv4address.length() == 0) {
throw new HSAdminException("no IPv4 address given");
}
try {
final InetAddress inetV4Address = InetAddress.getByName(ipv4address);
final String inetV4AddressString = inetV4Address.getHostAddress();
if (inetV4AddressString.startsWith(IPv4_83_223_79) // Alboin-Kontor Berlin
|| inetV4AddressString.startsWith(IPv4_83_223_91)
|| inetV4AddressString.startsWith(IPv4_83_223_95) ) {
return IPv6_PREFIX_AK;
}
if (inetV4AddressString.startsWith(IPv4_83_223_78) // e-Shelter Berlin
|| inetV4AddressString.startsWith(IPv4_83_223_94) ) {
return IPv6_PREFIX_ES;
}
} catch (UnknownHostException e) {
throw new HSAdminException(e);
}
throw new HSAdminException("unknown IPv4 address given");
}
public static boolean isKnownRemote(final String remoteAddress) { public static boolean isKnownRemote(final String remoteAddress) {
boolean isKnown = false; boolean isKnown = false;
if (remoteAddress.startsWith(IPv4_LOCALHOST) || remoteAddress.startsWith(IPv6_LOCALHOST) || remoteAddress.startsWith(IPv6_LOCALHOST_ALT)) { if (remoteAddress.startsWith(IPv4_LOCALHOST) || remoteAddress.startsWith(IPv6_LOCALHOST) || remoteAddress.startsWith(IPv6_LOCALHOST_ALT)) {