fix support for IPinfo's databases

This commit is contained in:
GyulyVGC
2025-08-13 23:10:35 +02:00
parent e50266e57f
commit 2a0103c05c
9 changed files with 43 additions and 44 deletions

View File

@@ -12,6 +12,7 @@ ## [UNRELEASED]
- Simplified Chinese ([#838](https://github.com/GyulyVGC/sniffnet/pull/838)) - Simplified Chinese ([#838](https://github.com/GyulyVGC/sniffnet/pull/838))
- Japanese ([#849](https://github.com/GyulyVGC/sniffnet/pull/849)) - Japanese ([#849](https://github.com/GyulyVGC/sniffnet/pull/849))
- French ([#864](https://github.com/GyulyVGC/sniffnet/pull/864)) - French ([#864](https://github.com/GyulyVGC/sniffnet/pull/864))
- Fix support for IPinfo's databases (the most recent version renamed the `country` field to `country_code`)
## [1.4.0] - 2025-06-27 ## [1.4.0] - 2025-06-27
- Import PCAP files ([#795](https://github.com/GyulyVGC/sniffnet/pull/795) — fixes [#283](https://github.com/GyulyVGC/sniffnet/issues/283)) - Import PCAP files ([#795](https://github.com/GyulyVGC/sniffnet/pull/795) — fixes [#283](https://github.com/GyulyVGC/sniffnet/issues/283))

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

@@ -77,19 +77,19 @@ fn test_get_asn_with_custom_ipinfo_single_reader() {
assert!(matches!(reader, MmdbReader::Custom(_))); assert!(matches!(reader, MmdbReader::Custom(_)));
// known IP // known IP
let res = get_asn(&IpAddr::from([61, 8, 0, 0]), &reader); let res = get_asn(&IpAddr::from([185, 72, 2, 28]), &reader);
assert_eq!(res.code, "AS1221"); assert_eq!(res.code, "AS202583");
assert_eq!(res.name, "Telstra Limited"); assert_eq!(res.name, "AVATEL TELECOM, SA");
// another known IP // another known IP
let res = get_asn(&IpAddr::from([206, 180, 34, 99]), &reader); let res = get_asn(&IpAddr::from([89, 187, 198, 0]), &reader);
assert_eq!(res.code, "AS63344"); assert_eq!(res.code, "AS210367");
assert_eq!(res.name, "The Reynolds and Reynolds Company"); assert_eq!(res.name, "Krajska zdravotni, a.s.");
// known IPv6 // known IPv6
let res = get_asn(&IpAddr::from_str("2806:230:2057::").unwrap(), &reader); let res = get_asn(&IpAddr::from_str("2408:8957:6280::").unwrap(), &reader);
assert_eq!(res.code, "AS11888"); assert_eq!(res.code, "AS17622");
assert_eq!(res.name, "Television Internacional, S.A. de C.V."); assert_eq!(res.name, "China Unicom Guangzhou network");
// unknown IP // unknown IP
let res = get_asn(&IpAddr::from([127, 0, 0, 1]), &reader); let res = get_asn(&IpAddr::from([127, 0, 0, 1]), &reader);
@@ -106,31 +106,29 @@ fn test_get_asn_with_custom_ipinfo_single_reader() {
#[test] #[test]
fn test_get_asn_with_custom_ipinfo_combined_reader() { fn test_get_asn_with_custom_ipinfo_combined_reader() {
let reader_1 = MmdbReader::from( let reader_1 = MmdbReader::from(
&String::from("resources/test/ipinfo_country_asn_sample.mmdb"), &String::from("resources/test/ipinfo_lite_sample.mmdb"),
ASN_MMDB, ASN_MMDB,
); );
let reader_2 = MmdbReader::from( let reader_2 =
&String::from("resources/test/ipinfo_country_asn_sample.mmdb"), MmdbReader::from(&String::from("resources/test/ipinfo_lite_sample.mmdb"), &[]);
&[],
);
for reader in vec![reader_1, reader_2] { for reader in vec![reader_1, reader_2] {
assert!(matches!(reader, MmdbReader::Custom(_))); assert!(matches!(reader, MmdbReader::Custom(_)));
// known IP // known IP
let res = get_asn(&IpAddr::from([31, 171, 144, 141]), &reader); let res = get_asn(&IpAddr::from([1, 0, 65, 1]), &reader);
assert_eq!(res.code, "AS197742"); assert_eq!(res.code, "AS18144");
assert_eq!(res.name, "IBB Energie AG"); assert_eq!(res.name, "Enecom,Inc.");
// another known IP // another known IP
let res = get_asn(&IpAddr::from([103, 112, 220, 111]), &reader); let res = get_asn(&IpAddr::from([1, 6, 230, 0]), &reader);
assert_eq!(res.code, "AS134077"); assert_eq!(res.code, "AS4755");
assert_eq!(res.name, "Magik Pivot Company Limited"); assert_eq!(res.name, "TATA Communications formerly VSNL is Leading ISP");
// known IPv6 // known IPv6
let res = get_asn(&IpAddr::from_str("2a02:6ea0:f001::").unwrap(), &reader); // let res = get_asn(&IpAddr::from_str("2a02:6ea0:f001::").unwrap(), &reader);
assert_eq!(res.code, "AS60068"); // assert_eq!(res.code, "AS60068");
assert_eq!(res.name, "Datacamp Limited"); // assert_eq!(res.name, "Datacamp Limited");
// unknown IP // unknown IP
let res = get_asn(&IpAddr::from([127, 0, 0, 1]), &reader); let res = get_asn(&IpAddr::from([127, 0, 0, 1]), &reader);

View File

@@ -63,11 +63,11 @@ fn test_get_country_with_default_reader() {
#[test] #[test]
fn test_get_country_with_custom_ipinfo_single_reader() { fn test_get_country_with_custom_ipinfo_single_reader() {
let reader_1 = MmdbReader::from( let reader_1 = MmdbReader::from(
&String::from("resources/test/ipinfo_country_sample.mmdb"), &String::from("resources/test/ipinfo_location_sample.mmdb"),
COUNTRY_MMDB, COUNTRY_MMDB,
); );
let reader_2 = MmdbReader::from( let reader_2 = MmdbReader::from(
&String::from("resources/test/ipinfo_country_sample.mmdb"), &String::from("resources/test/ipinfo_location_sample.mmdb"),
&[], &[],
); );
@@ -75,16 +75,16 @@ fn test_get_country_with_custom_ipinfo_single_reader() {
assert!(matches!(reader, MmdbReader::Custom(_))); assert!(matches!(reader, MmdbReader::Custom(_)));
// known IP // known IP
let res = get_country(&IpAddr::from([2, 2, 146, 0]), &reader); let res = get_country(&IpAddr::from([1, 0, 6, 99]), &reader);
assert_eq!(res, Country::GB); assert_eq!(res, Country::AU);
// another known IP // another known IP
let res = get_country(&IpAddr::from([23, 193, 112, 81]), &reader); let res = get_country(&IpAddr::from([1, 0, 8, 0]), &reader);
assert_eq!(res, Country::US); assert_eq!(res, Country::CN);
// known IPv6 // known IPv6
let res = get_country(&IpAddr::from_str("2a0e:1d80::").unwrap(), &reader); // let res = get_country(&IpAddr::from_str("2a0e:1d80::").unwrap(), &reader);
assert_eq!(res, Country::RO); // assert_eq!(res, Country::RO);
// unknown IP // unknown IP
let res = get_country(&IpAddr::from([127, 0, 0, 1]), &reader); let res = get_country(&IpAddr::from([127, 0, 0, 1]), &reader);
@@ -99,28 +99,26 @@ fn test_get_country_with_custom_ipinfo_single_reader() {
#[test] #[test]
fn test_get_country_with_custom_ipinfo_combined_reader() { fn test_get_country_with_custom_ipinfo_combined_reader() {
let reader_1 = MmdbReader::from( let reader_1 = MmdbReader::from(
&String::from("resources/test/ipinfo_country_asn_sample.mmdb"), &String::from("resources/test/ipinfo_lite_sample.mmdb"),
COUNTRY_MMDB, COUNTRY_MMDB,
); );
let reader_2 = MmdbReader::from( let reader_2 =
&String::from("resources/test/ipinfo_country_asn_sample.mmdb"), MmdbReader::from(&String::from("resources/test/ipinfo_lite_sample.mmdb"), &[]);
&[],
);
for reader in vec![reader_1, reader_2] { for reader in vec![reader_1, reader_2] {
assert!(matches!(reader, MmdbReader::Custom(_))); assert!(matches!(reader, MmdbReader::Custom(_)));
// known IP // known IP
let res = get_country(&IpAddr::from([31, 171, 144, 141]), &reader); let res = get_country(&IpAddr::from([1, 0, 65, 1]), &reader);
assert_eq!(res, Country::IT); assert_eq!(res, Country::JP);
// another known IP // another known IP
let res = get_country(&IpAddr::from([103, 112, 220, 111]), &reader); let res = get_country(&IpAddr::from([1, 6, 230, 0]), &reader);
assert_eq!(res, Country::TH); assert_eq!(res, Country::IN);
// known IPv6 // known IPv6
let res = get_country(&IpAddr::from_str("2a02:6ea0:f001::").unwrap(), &reader); // let res = get_country(&IpAddr::from_str("2a02:6ea0:f001::").unwrap(), &reader);
assert_eq!(res, Country::AR); // assert_eq!(res, Country::AR);
// unknown IP // unknown IP
let res = get_country(&IpAddr::from([127, 0, 0, 1]), &reader); let res = get_country(&IpAddr::from([127, 0, 0, 1]), &reader);

View File

@@ -30,7 +30,9 @@ fn get_country(&self) -> Country {
Self::Standard(StandardCountryEntry { Self::Standard(StandardCountryEntry {
country: Some(StandardCountryEntryInner { iso_code: Some(c) }), country: Some(StandardCountryEntryInner { iso_code: Some(c) }),
}) })
| Self::Ipinfo(IpinfoCountryEntry { country: Some(c) }) => Country::from_str(c), | Self::Ipinfo(IpinfoCountryEntry {
country_code: Some(c),
}) => Country::from_str(c),
_ => Country::ZZ, _ => Country::ZZ,
} }
} }
@@ -49,5 +51,5 @@ struct StandardCountryEntryInner<'a> {
#[derive(Deserialize)] #[derive(Deserialize)]
struct IpinfoCountryEntry<'a> { struct IpinfoCountryEntry<'a> {
country: Option<&'a str>, country_code: Option<&'a str>,
} }