echoip

repository·master·Indexed 26 days ago

https://github.com/mpolden/echoip

A simple service for looking up IP addresses, providing geolocation (city, country, ASN) and port testing capabilities. It serves as the engine behind ifconfig.co and offers endpoints for retrieving IP information in plain text or JSON, as well as a CLI for local deployment with support for MaxMind GeoIP databases.

Tokens
1.1K
Snippets
7
Records
10
Agent score
38%

What's inside echoip

  1. Download MaxMind GeoIP databases

    master

    To use geolocation features (city, country, ASN) when running the service locally, you must download the MaxMind GeoIP databases. This requires a MaxMind account and license key.

    GEOIP_LICENSE_KEY=<key> MAXMIND_ACCOUNT_ID=<account-id> make geoip-download
  2. Test port reachability

    master

    You can check if a specific port is reachable from a given IP using the /port/{port} endpoint. This returns a JSON object indicating the IP, the port, and whether it is reachable.

    $ curl ifconfig.co/port/80
    {
      "ip": "127.0.0.1",
      "port": 80,
      "reachable": false
    }
  3. Retrieve IP information as JSON

    master

    To get a complete JSON object containing the IP, city, country, country ISO, ASN, and ASN organization, set the Accept header to application/json or use the /json endpoint.

    $ curl -H 'Accept: application/json' ifconfig.co
    {
      "city": "Bornyasherk",
      "country": "Elbonia",
      "country_iso": "EB",
      "ip": "127.0.0.1",
      "ip_decimal": 2130706433,
      "asn": "AS31337",
      "asn_org": "Dilbert Technologies"
    }
  4. Lookup geolocation and ASN information

    master

    The service provides specific endpoints for retrieving geolocation and Autonomous System Number (ASN) details:

    • /country: Returns the country name.
    • /country-iso: Returns the ISO country code.
    • /city: Returns the city name.
    • /asn: Returns the ASN.
    • /asn-org: Returns the ASN organization name.

    You can also specify a custom IP address using the ?ip= query parameter on these endpoints.

    $ curl ifconfig.co/country
    Elbonia
    
    $ curl ifconfig.co/country-iso
    EB
    
    $ curl ifconfig.co/city
    Bornyasherk
    
    $ curl ifconfig.co/asn
    AS31337
    
    $ curl ifconfig.co/asn-org
    Dilbert Technologies
  5. echoip CLI reference

    master

    The echoip binary accepts several flags for configuration when running the service locally:

    FlagTypeDescription
    -CintSize of response cache. Set to 0 to disable
    -HvalueHeader to trust for remote IP, if present (e.g. X-Real-IP)
    -PEnables profiling handlers
    -astringPath to GeoIP ASN database
    -cstringPath to GeoIP city database
    -fstringPath to GeoIP country database
    -lstringListening address (default ":8080")
    -pEnable port lookup
    -rPerform reverse hostname lookups
    -sShow sponsor logo
    -tstringPath to template dir (default "html")
  6. Configure echoip CLI flags

    master

    The following flags are available for the echoip command:

    FlagTypeDescription
    -fstringPath to GeoIP country database
    -cstringPath to GeoIP city database
    -astringPath to GeoIP ASN database
    -lstringListening address (default: :8080)
    -rboolPerform reverse hostname lookups
    -pboolEnable port lookup
    -tstringPath to template dir (default: html)
    -CintSize of response cache. Set to 0 to disable
    -PboolEnables profiling handlers
    -sboolShow sponsor logo
    -HstringHeader to trust for remote IP, if present (e.g. X-Real-IP). Can be used multiple times.
  7. Use the echoip CLI

    master
    The echoip CLI tool provides a service that returns geolocation and network information based on the requester's IP address. You can configure it using various flags to specify GeoIP database paths, listening addresses, and lookup behaviors.