From 8f8f8a3dff3aecc703a29162b06b5776e8a83754 Mon Sep 17 00:00:00 2001 From: Yoo1tic <137816438+Yoo1tic@users.noreply.github.com> Date: Mon, 7 Jul 2025 01:12:08 +0800 Subject: [PATCH] feat: update README and main.rs to enhance proxy support with authentication details --- README.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++------ src/main.rs | 13 +++++++++-- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bef8a1e..9837908 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,61 @@ # Gemini-Keychecker -A tool to check and backup API keys +A tool to validate Google Gemini API keys. + +## Usage + +### Basic Usage + +```bash +# Validate keys from keys.txt and save valid ones to output_keys.txt +./target/release/gemini-keychecker + +# Specify custom input and output files +./target/release/gemini-keychecker -i my_keys.txt -o valid_keys.txt +``` + +### Advanced Usage + +```bash +# Use proxy with authentication +./target/release/gemini-keychecker -x http://username:password@proxy.example.com:8080 + +# Adjust concurrency and timeout +./target/release/gemini-keychecker -c 50 -t 30 + +# Use custom API host +./target/release/gemini-keychecker -u https://custom-api.googleapis.com/ +``` + +## Command Line Options + ``` Options: - -i, --input-path [default: keys.txt] - -o, --output-path [default: output_keys.txt] - -u, --api-host [default: https://generativelanguage.googleapis.com/] - -t, --timeout-ms [default: 5000] - -c, --concurrency [default: 30] - ``` \ No newline at end of file + -i, --input-path Input file containing API keys [default: keys.txt] + -o, --output-path Output file for valid keys [default: output_keys.txt] + -u, --api-host API host URL [default: https://generativelanguage.googleapis.com/] + -t, --timeout-sec Request timeout in seconds [default: 60] + -c, --concurrency Max concurrent requests [default: 30] + -x, --proxy Proxy URL (supports http://user:pass@host:port) + -h, --help Print help + -V, --version Print version +``` + +## Input Format + +Create a text file with one API key per line + +## Proxy Configuration + +The tool supports HTTP/HTTPS proxies with optional authentication: + +```bash +# HTTP proxy without authentication +./target/release/gemini-keychecker -x http://proxy.example.com:8080 + +# HTTP proxy with authentication +./target/release/gemini-keychecker -x http://username:password@proxy.example.com:8080 + +# HTTPS proxy with authentication +./target/release/gemini-keychecker -x https://user:pass@secure-proxy.com:8443 +``` diff --git a/src/main.rs b/src/main.rs index ad9b076..15f11ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,7 @@ struct KeyCheckerConfig { #[arg(long, short = 'c', default_value_t = 30)] concurrency: usize, - /// Optional proxy URL for HTTP requests + /// Optional proxy URL for HTTP requests (supports http://user:pass@host:port) #[arg(long, short = 'x')] proxy: Option, } @@ -163,7 +163,16 @@ fn build_client(config: &KeyCheckerConfig) -> Result { // Add proxy configuration if specified if let Some(proxy_url) = &config.proxy { - client_builder = client_builder.proxy(reqwest::Proxy::all(proxy_url.clone())?); + let mut proxy = reqwest::Proxy::all(proxy_url.clone())?; + + // Extract username and password from URL if present + if !proxy_url.username().is_empty() { + let username = proxy_url.username(); + let password = proxy_url.password().unwrap_or(""); + proxy = proxy.basic_auth(username, password); + } + + client_builder = client_builder.proxy(proxy); } client_builder.build().map_err(Into::into)