Skip to content

An API server that allows you to check the Public IP version 4/6

License

Notifications You must be signed in to change notification settings

leelsey/ipby-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IPby API

Usage

Service

curl https://api.ipby.net

Self-hosting

ipby-server --ip 0.0.0.0 --port 3000
curl http://SERVER_IP:3000

Routing

You can use it by accessing api.ipby.net. You can use each route as follows.

Path Method Description
/ GET/POST Returns the client's IP as text
/ip GET/POST Returns the client's IP version 4 or 6 as text
/ipv4 GET/POST Returns the client's IP version 4 as text
/ipv6 GET/POST Returns the client's IP version 6 as text
/xff GET/POST Returns the client's X-Forwarded-For header
/:format GET/POST Returns the client's IP as each format
/:format/ip GET/POST Returns the client's IP version 4 or 6 as each format
/:format/ipv4 GET/POST Returns the client's IP version 4 as each format
/:format/ipv6 GET/POST Returns the client's IP version 6 as each format

Supported Format

Format MIME
text text/plain
json application/json
yaml application/yaml
toml application/toml
xml application/xml

Build

1) Build

It is served by own server.

cargo build --release --bin ipby-server --features ipby-server

This is CURL for testing.

curl -H "x-forwarded-for: 9.9.9.9" localhost:3000/ip

2) AWS

When you run this, you need cargo-lambda. And default build target is --arm64 for Amazon Linux 2023 (arm64).

2-1) Lambda

It is served by Lambda’s Function URL.

cargo lambda build --release --arm64 --output-format zip --bin aws-lambda --features aws-lambda

This is AWS Lambda’s Test Event for testing.

{
  "resource": "/{proxy+}",
  "path": "/ip",
  "httpMethod": "GET",
  "headers": {
    "x-forwarded-for": "9.9.9.9"
  },
  "requestContext": {
    "resourcePath": "/{proxy+}",
    "httpMethod": "GET",
    "path": "/ip"
  },
  "body": null,
  "isBase64Encoded": false
}

2-2) AWS Lambda with API Gateway (HTTP API)

Warning

API Gateway does not currently support IP version 6.

This is serviced by linking Lambda and API Gateway.

cargo lambda build --release --arm64 --output-format zip --bin aws-api --features aws-api

This is AWS Lambda’s Test Event for testing.

{
  "path": "/ip",
  "httpMethod": "GET",
  "headers": {
    "Accept": "*/*",
    "x-forwarded-for": "9.9.9.9"
  },
  "queryStringParameters": null,
  "body": null,
  "isBase64Encoded": false
}

Development

If you use rust-analyzer and have proc macro main not expanded: No proc-macros present for craterust-analyzerunresolved-proc-macro error, you need disable it.

This is VSCode’s Settings for disabling it.

{
  "rust-analyzer.procMacro.enable": false
}

Releases

No releases published

Packages

No packages published

Languages