Skip to content

UltraSive/go-looking-glass-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Looking Glass Server

A lightweight, self-hosted Looking Glass web API written in Go that allows users to run network diagnostic commands like ping and mtr (My Traceroute) on demand. Supports both streaming and non-streaming output modes.


Features

  • Run ping or mtr to test connectivity from your server
  • Stream results in real-time using NDJSON
  • Validate IPv4 and domain targets
  • Easy to deploy with Docker
  • Written with chi and idiomatic Go

🚀 Quick Start

Prerequisites

  • Go 1.20+
  • Docker (optional, for containerized deployment)

Local Build and Run

go build -o looking-glass
./looking-glass

🐳 Docker

Build Image

docker build -t go-looking-glass .

Run Container

docker run --rm -p 8080:8080 go-looking-glass

API Usage

GET /ping

Ping a target.

Query Parameters:

Param Description Required Example
target Domain or IPv4 to ping 8.8.8.8
streaming Enable streaming via NDJSON true or false

Examples:

  • Non-streaming:

    curl "http://localhost:8080/ping?target=8.8.8.8"
  • Streaming:

    curl "http://localhost:8080/ping?target=8.8.8.8&streaming=true"

GET /mtr

Run MTR (My Traceroute) with --raw and 10 report cycles.

Query Parameters:

Param Description Required Example
target Domain or IPv4 to trace google.com
streaming Enable streaming via NDJSON true or false

Examples:

  • Non-streaming:

    curl "http://localhost:8080/mtr?target=google.com"
  • Streaming:

    curl "http://localhost:8080/mtr?target=google.com&streaming=true"

How It Works

  • Uses Go's os/exec to run ping and mtr
  • Parses the output line-by-line
  • Sends back structured JSON or NDJSON if streaming
  • Validates input to prevent command injection or malformed requests

🔐 Security Notes

  • Validates IPv4 addresses and domain formats
  • Does not support IPv6 (yet)
  • Make sure to secure your deployment (e.g., with reverse proxy, auth, rate limiting)

Tech Stack

  • Go
  • Chi Router
  • mtr, ping (must be installed in the container or host)

Roadmap

  • Add IPv6 support
  • WebSocket streaming support
  • UI dashboard

Sample Output

Streaming Ping

{"type":"ping","seq":1,"rtt_ms":12.7}
{"type":"ping","seq":2,"rtt_ms":12.9}

Non-Streaming MTR

[
  {"type":"hop","hop":1,"ip":"192.168.1.1"},
  {"type":"ping","hop":1,"rtt":15,"cycle_id":1},
  ...
]

License

MIT License. Feel free to use and modify.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published