Skip to content

Commit

Permalink
Update ipmon server
Browse files Browse the repository at this point in the history
  • Loading branch information
psidex committed Jul 22, 2023
1 parent f098e35 commit 90b28f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/bin/ipmon-server.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::net::SocketAddr;

use axum::{extract::ConnectInfo, http::header::HeaderMap, routing::get, Router};
use log::info;

use ipmon::platform;

#[tokio::main]
async fn main() {
simple_logger::init_with_level(log::Level::Info).unwrap();

let app = Router::new().route("/", get(handler));

let ip = match platform::is_debug() {
Expand All @@ -28,5 +31,6 @@ async fn handler(headers: HeaderMap, ConnectInfo(addr): ConnectInfo<SocketAddr>)
} else {
client_ip = addr.to_string();
}
info!("Request from: {}", client_ip);
client_ip
}
2 changes: 1 addition & 1 deletion src/bin/ipmon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const IP_CACHE_PATH: &str = "./ipmon.cache";
const SLEEP_TIME_SECONDS: u64 = 60;

fn get_current_ipv4() -> Result<Ipv4Addr, Box<dyn Error>> {
let get = reqwest::blocking::get("https://checkip.amazonaws.com/")?;
let get = reqwest::blocking::get("https://ip.simonj.dev/")?;
let ip = match platform::is_debug() {
true => Ipv4Addr::from_str("127.0.0.1")?,
false => get.text()?.parse::<Ipv4Addr>()?,
Expand Down

0 comments on commit 90b28f0

Please sign in to comment.