Skip to content

Commit 57a653f

Browse files
committed
Added support for AS domain, AS usage type and AS CIDR
1 parent e4b46f8 commit 57a653f

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ip2location"
3-
version = "0.5.4"
3+
version = "0.6.0"
44
authors = ["MARIRS <marirs@gmail.com>"]
55
description = "Find geo information & proxy information based on the given IP using IP2Location BIN databases"
66
keywords = ["ip2location", "geoip", "geolocation", "ip", "proxy"]

src/ip2location/consts.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,12 @@ pub const ASN_POSITION: [u32; 27] = [
7070
pub const AS_POSITION: [u32; 27] = [
7171
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
7272
];
73+
pub const ASDOMAIN_POSITION: [u32; 27] = [
74+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26,
75+
];
76+
pub const ASUSAGETYPE_POSITION: [u32; 27] = [
77+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27,
78+
];
79+
pub const ASCIDR_POSITION: [u32; 27] = [
80+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28,
81+
];

src/ip2location/db.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,27 @@ impl LocationDB {
399399
.read_u32((row_addr + 4 * (AS_POSITION[self.db_type as usize] - 1)).into())?;
400400
result.as_name = Some(self.source.read_str(index.into())?);
401401
}
402+
403+
if ASDOMAIN_POSITION[self.db_type as usize] > 0 {
404+
let index = self
405+
.source
406+
.read_u32((row_addr + 4 * (ASDOMAIN_POSITION[self.db_type as usize] - 1)).into())?;
407+
result.as_domain = Some(self.source.read_str(index.into())?);
408+
}
409+
410+
if ASUSAGETYPE_POSITION[self.db_type as usize] > 0 {
411+
let index = self
412+
.source
413+
.read_u32((row_addr + 4 * (ASUSAGETYPE_POSITION[self.db_type as usize] - 1)).into())?;
414+
result.as_usage_type = Some(self.source.read_str(index.into())?);
415+
}
416+
417+
if ASCIDR_POSITION[self.db_type as usize] > 0 {
418+
let index = self
419+
.source
420+
.read_u32((row_addr + 4 * (ASCIDR_POSITION[self.db_type as usize] - 1)).into())?;
421+
result.as_cidr = Some(self.source.read_str(index.into())?);
422+
}
402423
Ok(result)
403424
}
404425
}

src/ip2location/record.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ pub struct LocationRecord<'a> {
4141
pub district: Option<Cow<'a, str>>,
4242
pub asn: Option<Cow<'a, str>>,
4343
pub as_name: Option<Cow<'a, str>>,
44+
pub as_domain: Option<Cow<'a, str>>,
45+
pub as_usage_type: Option<Cow<'a, str>>,
46+
pub as_cidr: Option<Cow<'a, str>>,
4447
}
4548

4649
impl LocationRecord<'_> {
@@ -77,6 +80,9 @@ impl Default for LocationRecord<'_> {
7780
district: None,
7881
asn: None,
7982
as_name: None,
83+
as_domain: None,
84+
as_usage_type: None,
85+
as_cidr: None,
8086
}
8187
}
8288
}

0 commit comments

Comments
 (0)