Skip to content

Commit

Permalink
Version 1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DenuxPlays committed Dec 12, 2024
1 parent 270b447 commit b23b512
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 138 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ We do this to make it easier to read when using `cargo-dist` to generate the rel

### Fixed

- docker workflow
- docker workflow#

### Changed

- optimized ipifiy implementation

## Version 1.5.0 (12.12.2024)

Expand Down
120 changes: 1 addition & 119 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dyncloud"
version = "1.5.0"
version = "1.5.1"
authors = ["Timon Klinkert <[email protected]>"]
description = "A programm that handles updating DNS records with your current public IP address for Cloudflare."
license = "GPL-3"
Expand Down Expand Up @@ -40,12 +40,7 @@ serde = { version = "1.0.216", features = ["derive"] }

# HTTP client
reqwest = { version = "0.12.9", features = [
"brotli",
"gzip",
"deflate",
"zstd",
"rustls-tls",
"json",
"charset",
"http2",
"macos-system-configuration"
Expand Down
18 changes: 6 additions & 12 deletions src/ip/ip_getter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use serde::Deserialize;
use std::net::{Ipv4Addr, Ipv6Addr};

pub async fn get_public_ipv4_address() -> Ipv4Addr {
Expand All @@ -15,27 +14,22 @@ pub async fn get_public_ipv6_address() -> Ipv6Addr {
}
}

#[derive(Debug, Deserialize)]
struct IpifyResponse {
pub ip: String,
}

pub const IPIFY_V4_URL: &str = "https://api.ipify.org?format=json";
pub const IPIFY_V6_URL: &str = "https://api64.ipify.org?format=json";
pub const IPIFY_V4_URL: &str = "https://api.ipify.org";
pub const IPIFY_V6_URL: &str = "https://api6.ipify.org";

#[derive(Debug)]
pub struct IpGetter;

impl IpGetter {
pub async fn get_public_ipv4() -> Result<Ipv4Addr, anyhow::Error> {
let resp = reqwest::get(IPIFY_V4_URL).await?.json::<IpifyResponse>().await?;
let resp = reqwest::get(IPIFY_V4_URL).await?.text().await?;

Ok(resp.ip.parse()?)
Ok(resp.parse()?)
}

pub async fn get_public_ipv6() -> Result<Ipv6Addr, anyhow::Error> {
let resp = reqwest::get(IPIFY_V6_URL).await?.json::<IpifyResponse>().await?;
let resp = reqwest::get(IPIFY_V6_URL).await?.text().await?;

Ok(resp.ip.parse()?)
Ok(resp.parse()?)
}
}

0 comments on commit b23b512

Please sign in to comment.