added ip retrieval

This commit is contained in:
delorean 2025-01-12 13:05:06 -06:00
parent 2c8a2b4121
commit 6b2df7ddca
3 changed files with 25 additions and 4 deletions

View File

@ -6,6 +6,7 @@ pub const VERSION: &str = "1.2";
pub struct Params { pub struct Params {
pub statcodes: Vec<u16>, pub statcodes: Vec<u16>,
pub exclude: bool, pub exclude: bool,
pub ip: bool,
pub titles: bool, pub titles: bool,
pub favicon: bool, pub favicon: bool,
pub timestamps: bool, pub timestamps: bool,
@ -39,6 +40,10 @@ pub struct Config {
/// status codes to exclude, comma separated /// status codes to exclude, comma separated
pub excludecodes: Option<String>, pub excludecodes: Option<String>,
#[clap(long = "ip")]
/// include ip address
pub ip: bool,
#[clap(long = "title")] #[clap(long = "title")]
/// retrieve http titles /// retrieve http titles
pub pulltitles: bool, pub pulltitles: bool,
@ -86,6 +91,6 @@ pub fn setparams(c: &Config) -> Params {
exclude = true; 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 } timestamps: c.timestamps, bodysize: c.bodysize }
} }

View File

@ -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!( format!(
"{} {} {}", "{} {} {}",
fmtcode(sc), fmtcode(sc),

View File

@ -1,7 +1,7 @@
use reqwest::{redirect::Policy, Client}; use reqwest::{redirect::Policy, Client};
use std::time::Duration; use std::time::Duration;
use super::console::{parsehit, tstamp}; use super::console::{parsestatus, parseip, tstamp};
use super::conf::Params; use super::conf::Params;
use super::modules::*; 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(); let sc = response.status().as_u16();
if !params.statcodes.is_empty() { if !params.statcodes.is_empty() {
@ -61,7 +65,11 @@ pub async fn query(
let body_raw = readnbody(response, 10485760).await?; let body_raw = readnbody(response, 10485760).await?;
let body = body_str(body_raw).unwrap_or("error parsing response body".to_string()); 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 { if params.timestamps {
out = format!("{} {}", tstamp(), out); out = format!("{} {}", tstamp(), out);