HTTP server to echo the request's IP as the HTTP response body
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

IP echo

Super simple HTTP service to echo the request's IP address as the HTTP response body.

Supports sitting behind proxies using the X-Forwarded-For header.

It will reply to all HTTP requests with the origin IP (or the first IP in X-Forwarded-For if it's set), as well as print the ip address to stdout for logging, debugging, or whatever you fancy. Eg.

$ curl localhost:8080

It also has IPv6 support:

$ curl localhost:8080


Install golang then compile:

$ sudo apt-get install golang
$ go build -o ip-echo

This creates a binary at ./ip-echo. To run the service:

$ ./ip-echo



By default ip-echo will listen to port 8080. If you set up an environment variable called PORT then that will be used instead.

$ export PORT=80; ./ip-echo


IP echo simply logs the IP address it found out to standard output. You can redirect standard output to any file or program you like. You can add a timestamp on most unix systems by running the command like so:

$ ./ip-echo | while read line; do echo "[$(date --rfc-3339=seconds)] $line"; done
    [2014-12-27 00:01:15+00:00]

If you don't want to log, then you can redirect to /dev/null.


If you're using Ubuntu or Debian you can copy example-init.d-script/ip-echo in to /etc/init.d/.

This will allow you to start, stop, and restart ip-echo using service:

$ sudo service ip-echo status
    [ ok ] ip-echo service is running.

$ sudo service ip-echo stop
    [ ok ] Stopping ip-echo server: ip-echo.

$ sudo service ip-echo status
    [FAIL] ip-echo service is not running ... failed!

$ sudo service ip-echo start
    [ ok ] Starting ip-echo service: ip-echo.

This runs ip-echo with the following default parameters:


You can override these parameters by creating a file located at /etc/default/ip-echo and overriding any of the parameters listed in the same syntax and casing.

To configure Ubuntu or Debian to work with these defaults all you need to do is copy the ip-echo executable to /usr/sbin/:

$ sudo cp ip-echo /usr/sbin/

And add a user like so:

$ sudo useradd ip-echo

It's also easy to use ip-echo with chroot but that requires modifications to the init.d script.

To start ip-echo automatically when the server turns on run:

sudo update-rc.d ip-echo defaults