feat: initial ddns implementation

This commit is contained in:
2023-04-04 22:23:41 -07:00
parent 95259b545c
commit 5d835ace6b
6 changed files with 1153 additions and 7 deletions

7
.gitignore vendored
View File

@@ -1,16 +1,13 @@
# ---> Rust
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# Variables local to machine
.env.local

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"cSpell.words": ["ddns", "dotenv", "reqwest"]
}

1111
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

10
Cargo.toml Normal file
View File

@@ -0,0 +1,10 @@
[package]
name = "ddns"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dotenv = "0.15.0"
reqwest = { version = "0.11.16", features = ["blocking"] }

View File

@@ -1,3 +1,2 @@
# ddns
Small Rust program for updating Google dynamic dns
Small Rust program for updating Google dynamic dns

26
src/main.rs Normal file
View File

@@ -0,0 +1,26 @@
use dotenv;
use reqwest;
fn main() -> Result<(), reqwest::Error> {
dotenv::from_filename(".env.local").expect("No environment variables found");
let domain = std::env::var("GOOGLE_DOMAINS_DOMAIN").expect("GOOGLE_DOMAINS_DOMAIN is required");
let username = std::env::var("GOOGLE_DOMAINS_USERNAME").expect("GOOGLE_DOMAINS_USERNAME is required");
let password = std::env::var("GOOGLE_DOMAINS_PASSWORD").expect("GOOGLE_DOMAINS_PASSWORD is required");
let ip = reqwest::blocking::get("https://domains.google.com/checkip")?.text()?;
println!("{}", ip);
let client = reqwest::blocking::Client::new();
let update_response = client
.get(format!(
"https://domains.google.com/nic/update?hostname={}&myip={}",
domain, ip
))
.basic_auth(username, Some(password))
.send()?
.text()?;
println!("{}", update_response);
Ok(())
}