Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

icanhazrust - Rust Implementation

A simple web service that returns your IP address, inspired by icanhazip.com.

Features

  • Returns the client's IP address
  • Supports proxy headers (X-Forwarded-For, X-Real-IP, CF-Connecting-IP, etc.)
  • Optional JSON output via ?format=json parameter
  • Optional HTTP headers display via ?headers=true parameter
  • Can combine both parameters

Building

cargo build --release

Running

cargo run --release

The server will start on http://0.0.0.0:3000

Usage Examples

Plain text IP (default)

curl http://localhost:3000/
# Output: 127.0.0.1

JSON format

curl http://localhost:3000/?format=json
# Output:
# {
#   "ip": "127.0.0.1"
# }

Show HTTP headers

curl http://localhost:3000/?headers=true
# Output:
# 127.0.0.1
#
# Headers:
# host: localhost:3000
# user-agent: curl/7.88.1
# accept: */*

JSON with headers

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", "*/*"]
#   ]
# }

Configuration

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 port

Proxy Support

The service automatically detects the real client IP when behind a reverse proxy by checking these headers in order:

  1. X-Real-IP
  2. X-Forwarded-For (takes the first IP)
  3. CF-Connecting-IP (Cloudflare)
  4. True-Client-IP (Cloudflare Enterprise)
  5. X-Client-IP

If none are present, it falls back to the direct connection IP.

Dependencies

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages