Lizard ca4db18896 init
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00
2025-12-26 18:50:42 +03:00

IP Data API

A simple API for retrieving information about IP addresses.

Prerequisites

  • Go 1.20 or higher

Installation

  1. Clone the repository
  2. Install dependencies:
go mod tidy

Running the API

go run .

The server will start on port 8080 by default. You can change the port by setting the PORT environment variable.

Configuration

The API can be configured using the following environment variables:

Variable Description Default
PORT Port to run the API server 8080
DNS_TIMEOUT_MS Timeout for DNS hostname lookups in milliseconds 500
DISABLE_DNS_LOOKUP Disable hostname lookups completely for faster response (set to "true" or "1") disabled

Example:

DNS_TIMEOUT_MS=300 PORT=3000 go run .

# Run with DNS lookups disabled completely
DISABLE_DNS_LOOKUP=true go run .

API Endpoints

Get IP Information

GET /api/ip/:ip

Example:

GET /api/ip/8.8.8.8

Response:

{
  "ip": "8.8.8.8",
  "hostname": "dns.google",
  "asn": "15169",
  "as_name": "Google LLC",
  "country_code": "US",
  "country": "United States",
  "region": "California",
  "city": "Mountain View",
  "latitude": 37.40599,
  "longitude": -122.078514,
  "zip_code": "94043",
  "time_zone": "-07:00"
}

Performance Optimization

For maximum performance, you can completely disable hostname DNS lookups using the DISABLE_DNS_LOOKUP=true environment variable. This will make all API requests faster, but the hostname field will be empty in the response.

Features

  • IP geolocation data (country, region, city, coordinates, timezone)
  • ASN information (ASN number and organization name)
  • Hostname resolution via reverse DNS lookup (with configurable timeout or ability to disable)
  • Support for both IPv4 and IPv6 addresses
  • In-memory data storage with efficient binary search lookups

Data Sources

The API uses four data files:

IPv4 Files

  • IP2LOCATION-LITE-ASN.CSV - ASN information for IPv4 addresses
  • IP2LOCATION-LITE-DB11.CSV - Geolocation information for IPv4 addresses

IPv6 Files

  • IP2LOCATION-LITE-ASN.IPV6.CSV - ASN information for IPv6 addresses
  • IP2LOCATION-LITE-DB11.IPV6.CSV - Geolocation information for IPv6 addresses

These files are loaded into memory when the API starts. The API automatically detects whether an IP is IPv4 or IPv6 and uses the appropriate dataset.

Description
No description provided
Readme 221 MiB
Languages
Go 58.4%
HTML 41.4%
Batchfile 0.2%