added ip retrieval
This commit is contained in:
parent
2c8a2b4121
commit
6b2df7ddca
@ -6,6 +6,7 @@ pub const VERSION: &str = "1.2";
|
||||
pub struct Params {
|
||||
pub statcodes: Vec<u16>,
|
||||
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<String>,
|
||||
|
||||
#[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 }
|
||||
}
|
||||
|
@ -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),
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user