Add support for getting country codes for ASNs.

This commit is contained in:
Jon Chambers
2021-05-17 19:03:04 -04:00
committed by Jon Chambers
parent f8c623074b
commit b89de860d3
2 changed files with 22 additions and 7 deletions

View File

@@ -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")));