Skip to content

Commit 508a077

Browse files
committed
Added support for 6to4 and Teredo.
1 parent bdfae64 commit 508a077

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

com/ip2proxy/IP2Proxy.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public class IP2Proxy {
2323
private static final Pattern Pattern7 = Pattern.compile("^([0-9]+\\.){1,2}[0-9]+$");
2424
private static final BigInteger MAX_IPV4_RANGE = new BigInteger("4294967295");
2525
private static final BigInteger MAX_IPV6_RANGE = new BigInteger("340282366920938463463374607431768211455");
26+
private static final BigInteger FROM_6TO4 = new BigInteger("42545680458834377588178886921629466624");
27+
private static final BigInteger TO_6TO4 = new BigInteger("42550872755692912415807417417958686719");
28+
private static final BigInteger FROM_TEREDO = new BigInteger("42540488161975842760550356425300246528");
29+
private static final BigInteger TO_TEREDO = new BigInteger("42540488241204005274814694018844196863");
30+
private static final BigInteger LAST_32BITS = new BigInteger("4294967295");
31+
2632
private static final String MSG_NOT_SUPPORTED = "NOT SUPPORTED";
2733
private static final String MSG_INVALID_IP = "INVALID IP ADDRESS";
2834
private static final String MSG_MISSING_FILE = "MISSING FILE";
@@ -108,7 +114,7 @@ private enum Modes {
108114
private boolean AS_ENABLED;
109115
private boolean LASTSEEN_ENABLED;
110116

111-
private static final String _ModuleVersion = "2.0.0";
117+
private static final String _ModuleVersion = "2.1.0";
112118

113119
public IP2Proxy() {
114120

@@ -1112,8 +1118,21 @@ else if (Pattern2.matcher(IP).matches() || Pattern3.matcher(IP).matches() || Pat
11121118
else if (IA instanceof Inet4Address) { // this will run in cases of IPv4-mapped IPv6 addresses
11131119
IPType = "4";
11141120
}
1115-
A1 = new BigInteger(IPType);
11161121
A2 = new BigInteger(1, Bytes);
1122+
1123+
if (A2.compareTo(FROM_6TO4) >= 0 && A2.compareTo(TO_6TO4) <= 0) {
1124+
// 6to4 so need to remap to ipv4
1125+
IPType = "4";
1126+
A2 = A2.shiftRight(80);
1127+
A2 = A2.and(LAST_32BITS);
1128+
}
1129+
else if (A2.compareTo(FROM_TEREDO) >= 0 && A2.compareTo(TO_TEREDO) <= 0) {
1130+
// Teredo so need to remap to ipv4
1131+
IPType = "4";
1132+
A2 = A2.not();
1133+
A2 = A2.and(LAST_32BITS);
1134+
}
1135+
A1 = new BigInteger(IPType);
11171136
}
11181137
BigInteger[] BI = new BigInteger[] { A1, A2, A3 };
11191138

0 commit comments

Comments
 (0)