Giter Club home page Giter Club logo

ipecho's Introduction

ipecho

A very basic webserver that listens on port 80 and returns the apparent origin IP.

Built with gin.

Step 1: Build

Compiling requires Golang.

Clone the repo, move into the directory and run:

go build

This will compile to the binary file ipecho.

Step 2: Start listening

Port 80 requires root permissions, so you need to run the binary as root. For example:

# ./ipecho

Logging is done to STDOUT.

If you expect a reverse proxy to contact this application with headers that indicate the actual origin IP, such as X-Real-IP or X-Forwarded-For, you must indicate with a flag what the IP of this reverse proxy will be to mark it as trusted.

For example, if ipecho runs on 10.0.0.20 and a reverse proxy on 10.0.0.1, on the node that runs ipecho you would run:

# ./ipecho -proxy='10.0.0.1'

This flag can be specified multiple times to trust multiple proxies:

# ./ipecho -proxy='10.0.0.1' -proxy='10.0.0.2' (...)

Step 3: Examples

$ curl -s localhost/json | jq
{
  "IP": "127.0.0.1",
  "USERAGENT": "curl/7.85.0"
}
$ curl -s localhost
127.0.0.1

Dockerfile

In the same directory as Dockerfile, run:

$ docker build --tag ipecho .
(...)
Successfully built 2eeb58f23dac
Successfully tagged ipecho:latest
$ docker image ls
REPOSITORY   TAG               IMAGE ID       CREATED          SIZE
ipecho       latest            2eeb58f23dac   14 minutes ago   10.4MB

Start a container from the image (latest is implicit):

$ docker run --network=bridge -d ipecho
d240f5042683f299915b8c16f5c45cf2642ab4d69385c4c0c92a2523929ded1c

Figure out the IP and test it:

$ docker inspect d2 | grep IP
(...)
$ curl 172.17.0.2
172.17.0.1

ipecho's People

Contributors

lgrn avatar

Watchers

Christian W Utomo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.