+const FILE_CONF: &str = "config.ron";
+
+fn main() -> Result<()> {
+ println!("GANDI DynDNS");
+
+ let config = Config::read(FILE_CONF)?;
+
+ println!("Configuration: {:?}", config);
+
+ loop {
+ let time_beginning_loop = time::Instant::now();
+
+ check_and_update_dns(&config.api_key);
+
+ let elapsed = time::Instant::now() - time_beginning_loop;
+
+ if elapsed < config.delay_between_check {
+ let to_wait = config.delay_between_check - elapsed;
+ thread::sleep(to_wait);
+ }
+
+ }
+}
+
+fn check_and_update_dns(api_key: &str) {
+ /*
+ let url = "https://api.gandi.net/v5/livedns/domains";
+ let client = reqwest::blocking::Client::new();
+
+ match client.get(url).header("Authorization", format!("Apikey {}", api_key)).send() {
+ Ok(resp) =>
+ if resp.status().is_success() {
+ let content = resp.text().unwrap();
+ println!("Content:\n{:?}", content);
+ } else {
+ println!("Request unsuccessful:\n{:#?}", resp);
+ },
+ Err(error) =>
+ println!("Error during request: {:?}", error)
+ }
+ */
+ dbg!(get_real_ip());
+}
+
+fn get_real_ip() -> Result<Ipv4Addr> {
+
+ let url = "https://api.ipify.org";
+ let client = reqwest::blocking::Client::new();
+
+ match client.get(url).send() {
+ Ok(resp) =>
+ if resp.status().is_success() {
+ let content = resp.text().unwrap();
+ match content.parse::<IpAddr>() {
+ Ok(IpAddr::V4(ip_v4)) => Ok(ip_v4),
+ /*Err(_)*/ _ => Err(Box::new(GetRealIpError))
+ }
+ //println!("Content:\n{:?}", content);
+ } else {
+ println!("Request unsuccessful:\n{:#?}", resp);
+ Err(Box::new(GetRealIpError))
+ },