Add support for getting country codes for ASNs.

This commit is contained in:
Jon Chambers authored and Jon Chambers committed 2021-05-18 17:43:30 -04:00
1 parent f8c623074b
commit b89de860d3
2 files changed
+22 -7

No files matched your search

@@ -30,6 +30,17 @@ class AsnTableTest {
}
}
@Test
void getCountryCode() throws IOException {
try (final InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("ip2asn-test.tsv"))) {
final AsnTable asnTable = new AsnTable(reader);
assertEquals(Optional.of("US"), asnTable.getCountryCode(7922));
assertEquals(Optional.of("VN"), asnTable.getCountryCode(7552));
assertEquals(Optional.empty(), asnTable.getCountryCode(1234));
}
}
@Test
void ipToLong() throws UnknownHostException {
assertEquals(0x00000000ffffffffL, AsnTable.ipToLong((Inet4Address) Inet4Address.getByName("255.255.255.255")));