Returns IPv4 and IPV6 details similar to ifconfig.me website, for curl it will return just plain text response
Find a file
nahakubuilder 5d5d071d8e first
2026-10-25 09:14:28 +00:00
ipinfo first 2026-10-25 09:14:28 +00:00
.gitignore first 2026-10-25 09:14:28 +00:00
main.go first 2026-10-25 09:14:28 +00:00
main.go_Wrapper_sample first 2026-10-25 09:14:28 +00:00
README.md first 2026-10-25 09:14:28 +00:00

Go Ifconfig & Network Diagnostics Tool

A lightweight, single-executable web application built in Go that functions as a self-hosted IP and network diagnostics service (similar to ifconfig.me). It features intelligent CLI/browser detection, proxy header awareness, and lightning-fast local GeoIP/ASN lookups using IPinfo's free ipinfo_lite.mmdb database.


Features

  • Dual Interface (CLI & Browser): Automatically detects whether the request is coming from a command-line tool (curl, wget, httpie, etc.) or a web browser, returning clean text or an HTML dashboard accordingly.
  • Proxy-Aware: Fully supports reverse proxies and CDNs using headers like CF-Connecting-IP, X-Forwarded-For, and X-Real-IP.
  • Local Offline GeoIP & ASN Lookups: Utilizes IPinfo's free ipinfo_lite.mmdb database for fast, private, zero-latency location and AS network lookups.
  • Auto-Database Management: Automatically downloads the .mmdb file on startup and checks/updates it in the background based on a configurable interval.
  • Zero-Config First Run: Automatically generates an app.conf file on its first execution with sensible defaults.
  • Interactive Web Search: Includes an IP lookup search box on the web dashboard pre-filled with the client's detected IP address.

Endpoints

  • / — Web HTML dashboard (or plain-text IP when accessed via CLI). Supports querying specific IPs via ?ip=X.X.X.X.
  • /ip — Returns the client's IPv4 address.
  • /ip6 — Returns the client's IPv6 address.
  • /host — Returns the reverse DNS hostname for the client's IPv4 address.
  • /host6 — Returns the reverse DNS hostname for the client's IPv6 address.
  • /all — Returns a detailed JSON payload containing headers, client IPs, reverse DNS, and geo/ASN information.

Configuration (app.conf)

On its first run, the application automatically creates an app.conf file in the same directory as the executable:

# Ifconfig App Configuration
host = 0.0.0.0
port = 8080
ipinfo_token = YOUR_IPINFO_API_TOKEN_HERE
geoip_update_interval_hours = 168

  • host: The network interface address to bind to.
  • port: The port the web server listens on.
  • ipinfo_token: Your free token from IPinfo.io required to download and update the local ipinfo_lite.mmdb database.
  • geoip_update_interval_hours: Frequency in hours to check and refresh the local database file (default is 168 hours / 7 days).

Getting Started

1. Prerequisites

  • Go 1.22 or higher installed on your machine.

2. Project Structure

ipinfo/
├── go.mod
├── app.conf (Auto-generated)
├── ipinfo_lite.mmdb (Auto-downloaded)
├── main.go
└── ipinfo/
    ├── config.go
    ├── geoinfo.go
    └── server.go

3. Installation & Running

Initialize your module and install the required MMDB parser dependency:

go mod init ipinfo
go mod tidy
# go get github.com/oschwald/maxminddb-golang

Run the application:

go run main.go

To build a standalone executable:

go build -o ipinfo main.go


Usage Examples

From the Terminal (CLI):

curl http://localhost:8080

Query a specific IP via CLI:

curl "http://localhost:8080/all?ip=8.8.8.8"

Fetch JSON output:

curl http://localhost:8080/all