mirror of
https://github.com/edu4rdshl/fhc.git
synced 2026-07-17 23:24:50 +00:00
Performance improvements + new flag.
This commit is contained in:
parent
9dafb942ce
commit
cd80d37153
3 changed files with 38 additions and 8 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -116,7 +116,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fhc"
|
name = "fhc"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"futures",
|
"futures",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "fhc"
|
name = "fhc"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
authors = ["Eduard Tolosa <edu4rdshl@protonmail.com>"]
|
authors = ["Eduard Tolosa <edu4rdshl@protonmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Fast HTTP Checker."
|
description = "Fast HTTP Checker."
|
||||||
|
|
@ -15,5 +15,5 @@ readme = "README.md"
|
||||||
tokio = { version = "0.2.22", features = ["full"] }
|
tokio = { version = "0.2.22", features = ["full"] }
|
||||||
futures = "0.3.5"
|
futures = "0.3.5"
|
||||||
clap = "2.33.3"
|
clap = "2.33.3"
|
||||||
reqwest = "0.10.8"
|
reqwest = { version = "0.10.8", features = ["default-tls"] }
|
||||||
openssl = { version = "0.10.30", features = ["vendored"] }
|
openssl = { version = "0.10.30", features = ["vendored"] }
|
||||||
|
|
|
||||||
40
src/main.rs
40
src/main.rs
|
|
@ -11,8 +11,8 @@ use {
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Eval args
|
// Eval args
|
||||||
let matches = App::new("Fhc")
|
let matches = App::new("FHC")
|
||||||
.version("0.1.0")
|
.version(clap::crate_version!())
|
||||||
.author("Eduard Tolosa <edu4rdshl@protonmail.com>")
|
.author("Eduard Tolosa <edu4rdshl@protonmail.com>")
|
||||||
.about("Fast HTTP Checker.")
|
.about("Fast HTTP Checker.")
|
||||||
.arg(
|
.arg(
|
||||||
|
|
@ -35,6 +35,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.help("User agent string."),
|
.help("User agent string."),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("ignore-certs")
|
||||||
|
.short("i")
|
||||||
|
.long("ignore-certs")
|
||||||
|
.takes_value(false)
|
||||||
|
.help("Accept invalid certificates when checking https. Default: false"),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("1xx")
|
Arg::with_name("1xx")
|
||||||
.short("1")
|
.short("1")
|
||||||
|
|
@ -88,10 +95,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
};
|
};
|
||||||
let threads = value_t!(matches.value_of("threads"), usize).unwrap_or_else(|_| 100);
|
let threads = value_t!(matches.value_of("threads"), usize).unwrap_or_else(|_| 100);
|
||||||
let timeout = value_t!(matches.value_of("timeout"), u64).unwrap_or_else(|_| 3);
|
let timeout = value_t!(matches.value_of("timeout"), u64).unwrap_or_else(|_| 3);
|
||||||
let user_agent = &value_t!(matches.value_of("user-agent"), String).unwrap_or_else(|_| "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36".to_string());
|
let user_agent = value_t!(matches.value_of("user-agent"), String).unwrap_or_else(|_| "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36".to_string());
|
||||||
|
let accept_ivalid_certs = matches.is_present("ignore-certs");
|
||||||
|
|
||||||
let client = reqwest::Client::builder()
|
let client = reqwest::Client::builder()
|
||||||
.timeout(std::time::Duration::from_secs(timeout))
|
.timeout(std::time::Duration::from_secs(timeout))
|
||||||
|
.danger_accept_invalid_certs(accept_ivalid_certs)
|
||||||
.user_agent(user_agent)
|
.user_agent(user_agent)
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
|
|
@ -103,11 +112,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
futures::stream::iter(hosts.into_iter().map(|host| {
|
futures::stream::iter(hosts.into_iter().map(|host| {
|
||||||
// HTTP/HTTP URLs
|
// HTTP/HTTP URLs
|
||||||
let https_url = format!("https://{}", host);
|
let https_url = format!("https://{}/", host);
|
||||||
let http_url = format!("http://{}", host);
|
let http_url = format!("http://{}/", host);
|
||||||
// Create futures
|
// Create futures
|
||||||
let https_send_fut = client.get(&https_url).send();
|
let https_send_fut = client.get(&https_url).send();
|
||||||
let http_send_fut = client.get(&http_url).send();
|
let http_send_fut = client.get(&http_url).send();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let mut response_code = 0;
|
let mut response_code = 0;
|
||||||
let mut valid_url = String::new();
|
let mut valid_url = String::new();
|
||||||
|
|
@ -118,6 +128,26 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
valid_url = http_url.to_string();
|
valid_url = http_url.to_string();
|
||||||
response_code = resp.status().as_u16()
|
response_code = resp.status().as_u16()
|
||||||
}
|
}
|
||||||
|
// Code for debugging issues when needed
|
||||||
|
// match https_send_fut.await {
|
||||||
|
// Ok(resp) => {
|
||||||
|
// valid_url = https_url.to_string();
|
||||||
|
// response_code = resp.status().as_u16();
|
||||||
|
// }
|
||||||
|
// Err(e) => {
|
||||||
|
// println!(
|
||||||
|
// "Err checking {}, description: {}\n Trying HTTP...",
|
||||||
|
// https_url, e
|
||||||
|
// );
|
||||||
|
// match http_send_fut.await {
|
||||||
|
// Ok(resp) => {
|
||||||
|
// valid_url = http_url.to_string();
|
||||||
|
// response_code = resp.status().as_u16();
|
||||||
|
// }
|
||||||
|
// Err(e) => println!("Err checking {}, description: {}", http_url, e),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
if !valid_url.is_empty() && conditional_response_code == 0 {
|
if !valid_url.is_empty() && conditional_response_code == 0 {
|
||||||
println!("{}", valid_url)
|
println!("{}", valid_url)
|
||||||
} else if (!valid_url.is_empty() && conditional_response_code != 0)
|
} else if (!valid_url.is_empty() && conditional_response_code != 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue