Return Optional.empty() for present-but-not-routed IPs.

This commit is contained in:
Jon Chambers 2021-05-18 17:17:20 -04:00 committed by Jon Chambers
parent b89de860d3
commit 94ac3f6cc8
3 changed files with 4 additions and 1 deletions

View File

@ -71,7 +71,8 @@ class AsnTable {
return Optional.ofNullable(asnBlocksByFirstIp.floorEntry(addressAsLong))
.filter(entry -> entry.getValue().contains(addressAsLong))
.map(entry -> entry.getValue().getAsn());
.map(entry -> entry.getValue().getAsn())
.filter(asn -> asn != 0);
}
public Optional<String> getCountryCode(final long asn) {

View File

@ -25,6 +25,7 @@ class AsnTableTest {
assertEquals(Optional.of(7922L), asnTable.getAsn((Inet4Address) Inet4Address.getByName("50.79.54.1")));
assertEquals(Optional.of(7552L), asnTable.getAsn((Inet4Address) Inet4Address.getByName("27.79.32.1")));
assertEquals(Optional.empty(), asnTable.getAsn((Inet4Address) Inet4Address.getByName("5.182.202.1")));
assertEquals(Optional.empty(), asnTable.getAsn((Inet4Address) Inet4Address.getByName("32.79.117.1")));
assertEquals(Optional.empty(), asnTable.getAsn((Inet4Address) Inet4Address.getByName("10.0.0.1")));
}

View File

@ -1,2 +1,3 @@
95865344 95865855 0 None Not routed
458051584 458227711 7552 VN VIETEL-AS-AP Viettel Group
843841536 844103679 7922 US COMCAST-7922 - Comcast Cable Communications, LLC

1 458051584 95865344 458227711 95865855 7552 0 VN None VIETEL-AS-AP Viettel Group Not routed
1 95865344 95865855 0 None Not routed
2 458051584 458051584 458227711 458227711 7552 7552 VN VN VIETEL-AS-AP Viettel Group VIETEL-AS-AP Viettel Group
3 843841536 843841536 844103679 844103679 7922 7922 US US COMCAST-7922 - Comcast Cable Communications, LLC COMCAST-7922 - Comcast Cable Communications, LLC