diff --git a/src/common/conf.rs b/src/common/conf.rs index 5b67b60..0e489c3 100755 --- a/src/common/conf.rs +++ b/src/common/conf.rs @@ -6,6 +6,7 @@ pub const VERSION: &str = "1.2"; pub struct Params { pub statcodes: Vec, pub exclude: bool, + pub ip: bool, pub titles: bool, pub favicon: bool, pub timestamps: bool, @@ -39,6 +40,10 @@ pub struct Config { /// status codes to exclude, comma separated pub excludecodes: Option, + #[clap(long = "ip")] + /// include ip address + pub ip: bool, + #[clap(long = "title")] /// retrieve http titles pub pulltitles: bool, @@ -86,6 +91,6 @@ pub fn setparams(c: &Config) -> Params { exclude = true; } - Params { statcodes, exclude, titles: c.pulltitles, favicon: c.favicon, + Params { statcodes, exclude, ip: c.ip, titles: c.pulltitles, favicon: c.favicon, timestamps: c.timestamps, bodysize: c.bodysize } } diff --git a/src/common/console.rs b/src/common/console.rs index 75de2ec..e49ddc8 100755 --- a/src/common/console.rs +++ b/src/common/console.rs @@ -74,7 +74,15 @@ pub fn parsehash(h: i32) -> String { ) } -pub fn parsehit(sc: u16, url: &String) -> String { +pub fn parseip(ip: String) -> String { + format!("{}{}{}", + "ip[".bright_black().bold(), + ip.bright_white().bold(), + "]".bright_black().bold() + ) +} + +pub fn parsestatus(sc: u16, url: &String) -> String { format!( "{} {} {}", fmtcode(sc), diff --git a/src/common/net.rs b/src/common/net.rs index a0903c4..ac29a61 100755 --- a/src/common/net.rs +++ b/src/common/net.rs @@ -1,7 +1,7 @@ use reqwest::{redirect::Policy, Client}; use std::time::Duration; -use super::console::{parsehit, tstamp}; +use super::console::{parsestatus, parseip, tstamp}; use super::conf::Params; use super::modules::*; @@ -43,6 +43,10 @@ pub async fn query( } } + let ip_addr = response.remote_addr() + .map(|addr| addr.ip().to_string()) + .unwrap_or("unknown".to_string()); + let sc = response.status().as_u16(); if !params.statcodes.is_empty() { @@ -61,7 +65,11 @@ pub async fn query( let body_raw = readnbody(response, 10485760).await?; let body = body_str(body_raw).unwrap_or("error parsing response body".to_string()); - let mut out = parsehit(sc, &url); + let mut out = parsestatus(sc, &url); + + if params.ip { + out = format!("{} {}", out, parseip(ip_addr)); + } if params.timestamps { out = format!("{} {}", tstamp(), out);