feat: initial ddns implementation
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -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
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"cSpell.words": ["ddns", "dotenv", "reqwest"]
|
||||
}
|
||||
1111
Cargo.lock
generated
Normal file
1111
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
Normal file
10
Cargo.toml
Normal 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"] }
|
||||
@@ -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
26
src/main.rs
Normal 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(())
|
||||
}
|
||||
Reference in New Issue
Block a user