A simple web service that returns your IP address, inspired by icanhazip.com.
- Returns the client's IP address
- Supports proxy headers (X-Forwarded-For, X-Real-IP, CF-Connecting-IP, etc.)
- Optional JSON output via
?format=jsonparameter - Optional HTTP headers display via
?headers=trueparameter - Can combine both parameters
cargo build --releasecargo run --releaseThe server will start on http://0.0.0.0:3000
curl http://localhost:3000/
# Output: 127.0.0.1curl http://localhost:3000/?format=json
# Output:
# {
# "ip": "127.0.0.1"
# }curl http://localhost:3000/?headers=true
# Output:
# 127.0.0.1
#
# Headers:
# host: localhost:3000
# user-agent: curl/7.88.1
# accept: */*curl http://localhost:3000/?format=json&headers=true
# Output:
# {
# "ip": "127.0.0.1",
# "headers": [
# ["host", "localhost:3000"],
# ["user-agent", "curl/7.88.1"],
# ["accept", "*/*"]
# ]
# }To change the listening port, modify the addr variable in main.rs:
let addr = SocketAddr::from(([0, 0, 0, 0], 8080)); // Change 3000 to your desired portThe service automatically detects the real client IP when behind a reverse proxy by checking these headers in order:
X-Real-IPX-Forwarded-For(takes the first IP)CF-Connecting-IP(Cloudflare)True-Client-IP(Cloudflare Enterprise)X-Client-IP
If none are present, it falls back to the direct connection IP.
axum- Web frameworktokio- Async runtimeserde/serde_json- JSON serializationtower/tower-http- Middleware and tracingtracing- Logging
MIT