Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IPv6 support #51

Merged
merged 1 commit into from
Jan 8, 2024
Merged

Add IPv6 support #51

merged 1 commit into from
Jan 8, 2024

Conversation

talhahwahla
Copy link
Contributor

No description provided.

@talhahwahla talhahwahla marked this pull request as ready for review January 8, 2024 10:00
@talhahwahla talhahwahla marked this pull request as draft January 8, 2024 10:16
@talhahwahla talhahwahla force-pushed the talhahwahla/ipv6-support branch 2 times, most recently from c427832 to 49a8826 Compare January 8, 2024 14:05
@talhahwahla
Copy link
Contributor Author

In this PR, I have moved the URL configuration from the context structure to functions. We have three public functions: get_map , lookup_batch and lookup. They will point to "https://ipinfo.io". I have added three new corresponding functions: get_map_v6 , lookup_batch_v6 and lookup_v6. They point to: "https://v6.ipinfo.io".

root@ipv6-test-server:~/rust# cat examples/lookup_batch.rs 
use ipinfo::{BatchReqOpts, IpInfo, IpInfoConfig};
use std::env;

#[tokio::main]
async fn main() {
    let token = env::args().nth(1);

    let config = IpInfoConfig {
        token,
        ..Default::default()
    };

    let mut ipinfo = IpInfo::new(config).expect("should construct");

    let res2 = ipinfo
        .lookup_batch_v6(&["2a00:1838:37:107::e3a6", "2a02:4780:10:5bae::1"], BatchReqOpts::default())
        .await;

    match res2 {
        Ok(r) => {
            println!("2a00:1838:37:107::e3a6: {:?}", r["2a00:1838:37:107::e3a6"]);
            println!("2a02:4780:10:5bae::1: {:?}", r["2a02:4780:10:5bae::1"]);
        }
        Err(e) => println!("error occurred: {}", &e.to_string()),
    }
}
root@ipv6-test-server:~/rust# cargo run --example lookup_batch -- <TOKEN>
   Compiling ipinfo v3.0.0 (/root/rust)
    Finished dev [unoptimized + debuginfo] target(s) in 7.99s
     Running `target/debug/examples/lookup_batch <TOKEN>`
2a00:1838:37:107::e3a6: IpDetails { ip: "2a00:1838:37:107::e3a6", hostname: None, city: "Saint Petersburg", region: "St.-Petersburg", country: "RU", country_name: Some("Russia"), is_eu: Some(false), country_flag: Some(CountryFlag { emoji: "🇷🇺", unicode: "U+1F1F7 U+1F1FA" }), country_flag_url: Some("https://cdn.ipinfo.io/static/images/countries-flags/RU.svg"), country_currency: Some(CountryCurrency { code: "RUB", symbol: "₽" }), continent: Some(Continent { code: "EU", name: "Europe" }), loc: "59.9386,30.3141", org: Some("AS43317 SIA VEESP"), postal: Some("190000"), timezone: Some("Europe/Moscow"), asn: Some(AsnDetails { asn: "AS43317", name: "SIA VEESP", domain: "veesp.com", route: "2a00:1838::/32", asn_type: "hosting" }), company: Some(CompanyDetails { name: "FNK LLC", domain: "rnet.ru", company_type: "business" }), carrier: None, privacy: Some(PrivacyDetails { vpn: true, proxy: false, tor: false, relay: false, hosting: true, service: "MaxiVPN" }), abuse: Some(AbuseDetails { address: "Tirgonju iela 17, LV3401, Liepaja, Latvia", country: "RU", email: "[email protected]", name: "Abuse-C Role", network: "2a00:1838::/32", phone: "" }), domains: Some(DomainsDetails { ip: None, total: 0, domains: [] }), bogon: None, extra: {} }
2a02:4780:10:5bae::1: IpDetails { ip: "2a02:4780:10:5bae::1", hostname: None, city: "Phoenix", region: "Arizona", country: "US", country_name: Some("United States"), is_eu: Some(false), country_flag: Some(CountryFlag { emoji: "🇺🇸", unicode: "U+1F1FA U+1F1F8" }), country_flag_url: Some("https://cdn.ipinfo.io/static/images/countries-flags/US.svg"), country_currency: Some(CountryCurrency { code: "USD", symbol: "$" }), continent: Some(Continent { code: "NA", name: "North America" }), loc: "33.4484,-112.0740", org: Some("AS47583 Hostinger International Limited"), postal: Some("85001"), timezone: Some("America/Phoenix"), asn: Some(AsnDetails { asn: "AS47583", name: "Hostinger International Limited", domain: "hostinger.com", route: "2a02:4780:10::/48", asn_type: "hosting" }), company: Some(CompanyDetails { name: "Hostinger International Limited", domain: "hostinger.com", company_type: "hosting" }), carrier: None, privacy: Some(PrivacyDetails { vpn: true, proxy: false, tor: false, relay: false, hosting: true, service: "Best Proxy Switcher" }), abuse: Some(AbuseDetails { address: "Europos pr. 32, LT-46326 Kaunas, Lithuania", country: "LT", email: "[email protected]", name: "Hostinger Administrators", network: "2a02:4780:10::/48", phone: "+37064503378" }), domains: Some(DomainsDetails { ip: None, total: 0, domains: [] }), bogon: None, extra: {} }

@talhahwahla talhahwahla marked this pull request as ready for review January 8, 2024 14:22
Copy link
Contributor

@UmanShahzad UmanShahzad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually dont need a _v6 on the map / batch funcs, just lookup. This is really only useful for getting your own v6 IP by force due to v6.ipinfo.io only having a AAAA record and no A record. Batch already supports doing /<v6_ip> within it.

@UmanShahzad UmanShahzad merged commit 8a54272 into master Jan 8, 2024
1 check passed
@UmanShahzad UmanShahzad deleted the talhahwahla/ipv6-support branch January 8, 2024 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants