Skip to content
zacconePublic

About

Ask me for an A or AAAA record and I will respond with your public IP address

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

35 Commits

Folders and files

Repository files navigation

goPubIP

A small UDP DNS server that replies to A and AAAA queries with the client's source IP address. Use it to discover the address the server sees for a client. It does not perform recursive DNS lookups.

Go CI

Installation

Requires Go 1.27 or newer.

go install github.com/zaccone/goPubIP@latest

The binary is installed in GOBIN, or $(go env GOPATH)/bin when GOBIN is unset. Add that directory to your PATH.

To build from source with the pinned module dependencies:

git clone https://github.com/zaccone/goPubIP.git
cd goPubIP
make all
./goPubIP

Run make install to install your local checkout, or make clean to remove local build output.

Quick start

Start a server on port 5300 that answers queries for ip.example.com.:

goPubIP -host ip.example.com.

In another terminal, query it with dig:

dig +short @127.0.0.1 -p 5300 ip.example.com. A
# 127.0.0.1

dig +short @127.0.0.1 -p 5300 ip.example.com. AAAA
# ::ffff:127.0.0.1

Replace 127.0.0.1 after @ with your server's address to query it remotely. The reply contains the source address seen by the server, which may be a NAT or DNS forwarder's address if the query passes through one.

Options

Short flag Long flag Default Description
-a -address 0.0.0.0 Address to listen on. Enclose IPv6 addresses in brackets.
-p -port 5300 UDP port to listen on.
-h -host . Query name to answer. . accepts any name.

A configured host must end with a dot, for example ip.example.com.. Host matching is exact, including letter case. Queries for other names receive an empty answer.

-h requires a host value; it is not a help flag. Display usage with:

goPubIP -help

With no options, the server listens on 0.0.0.0:5300 and accepts any query name. IPv6 availability on this wildcard listener depends on the operating system. To listen explicitly on IPv6 loopback:

goPubIP -address '[::1]' -port 5300 -host ip.example.com.

Query that listener from another terminal:

dig +short @::1 -p 5300 ip.example.com. AAAA
# ::1

Response behavior

Client source address Query type Answer
IPv4 A Client's IPv4 address
IPv4 AAAA IPv4-mapped IPv6 address, such as ::ffff:192.0.2.1
IPv6 AAAA Client's IPv6 address
IPv6 A Empty answer
Either Any other type Empty answer

Answers have a TTL of zero. Empty answers for unsupported types or host/address mismatches use the DNS NOERROR response code; they are not NXDOMAIN replies.

For example, an A query to the IPv6 loopback listener returns no answer records:

dig @::1 -p 5300 ip.example.com. A

Docker

Build the image from your checkout on Linux with Go, Make, Docker, and a CA certificate bundle at /etc/ssl/certs/ca-certificates.crt:

make container

The existing build target produces a static Linux binary for the build machine's architecture and packages it in a scratch image named zaccone/gopubip.

Run the locally built image and publish its UDP port:

docker run -d --name pubip -p 5300:5300/udp zaccone/gopubip -host ip.example.com.
docker logs pubip

Application flags go after the image name. To answer queries for any host, omit -host ip.example.com.. IPv6 access depends on your Docker host and network configuration.

Stop and remove the container when finished:

docker stop pubip
docker rm pubip

Development

go mod verify
go vet ./...
go test -race ./...
make build

The DNS library is codeberg.org/miekg/dns, the successor to github.com/miekg/dns. Its version is pinned because the upstream API is still evolving.

make deps downloads the versions pinned in go.mod and go.sum; it does not upgrade them.

License

MIT

About

Ask me for an A or AAAA record and I will respond with your public IP address

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages