feat: update README and main.rs to enhance proxy support with authentication details

main
Yoo1tic 2025-07-07 01:12:08 +08:00
parent 25e89d8610
commit 8f8f8a3dff
2 changed files with 68 additions and 9 deletions

View File

@ -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 <INPUT_PATH> [default: keys.txt]
-o, --output-path <OUTPUT_PATH> [default: output_keys.txt]
-u, --api-host <API_HOST> [default: https://generativelanguage.googleapis.com/]
-t, --timeout-ms <TIMEOUT_MS> [default: 5000]
-c, --concurrency <CONCURRENCY> [default: 30]
```
-i, --input-path <INPUT_PATH> Input file containing API keys [default: keys.txt]
-o, --output-path <OUTPUT_PATH> Output file for valid keys [default: output_keys.txt]
-u, --api-host <API_HOST> API host URL [default: https://generativelanguage.googleapis.com/]
-t, --timeout-sec <TIMEOUT_SEC> Request timeout in seconds [default: 60]
-c, --concurrency <CONCURRENCY> Max concurrent requests [default: 30]
-x, --proxy <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
```

View File

@ -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<Url>,
}
@ -163,7 +163,16 @@ fn build_client(config: &KeyCheckerConfig) -> Result<Client> {
// 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)