Skip to content

pfoo/ifconfig.pm

 
 

Repository files navigation

ifconfig.pm

README

This is a slightly modified version of https://github.com/georgyo/ifconfig.io :

  • Support for HTTP Connection, Charset, Via, Do-Not-Track and Cache-Control headers
  • Added Protocol field and a way of displaying the original protocol if running behind an HTTP proxy
  • Added a way to support real client port when the app is run behind an HTTP proxy
  • wget and fetch are treated like curl (providing value without html formating)
  • show IP country and AS name/number based on MaxMind GeoLite2 free database using https://github.com/oschwald/maxminddb-golang

Build instruction :

A few parameters can be defined using export before launching the binary :

  • export GIN_MODE=debug|release
  • export HTTP_PORT="8080"
  • export HTTP_HOST="127.0.0.1"
  • export FCGI_PORT="4000"
  • export FCGI_HOST="127.0.0.1"
  • export PROXY_TYPE="FCGI|HTTP|BOTH"

Required for ip country and ASN support :

Running behind an HTTP proxy :

  • Run the go program on 127.0.0.1:8080 with PROXY_TYPE environement variable set to HTTP
  • Use apache mod_proxy_http to proxy requests from apache to http://127.0.0.1:8080/
  • Add followings headers to the proxyfied requests :
    CF-Connecting-IP : The IP address the client is connecting from. Important or the IP will be wrong.
    CF-Connecting-PORT : The port the client is connecting from. Important or the PORT will be wrong.
    CF-Connection : HTTP_CONNECTION header sent by the client to the proxy
    CF-Protocol : The HTTP protocol the client is connecting with. Important or the displayed protocol will be wrong.
  • See example apache.http.conf

Running behind an FCGI proxy :

  • Run the go program on 127.0.0.1:4000 with PROXY_TYPE environement variable set to FCGI
  • Use apache mod_proxy_fcgi to proxy requests from apache to fcgi://127.0.0.1:4000/
  • See example apache.fcgi.conf

Running behind systemd socket activation (see http://0pointer.de/blog/projects/socket-activation.html)

  • Run : systemd-socket-activate -l 8000 ./ifconfig.pm
  • systemd will listen on port 8000, start the program only when required and forward everything to it using socket
  • If everything is working, you can create two files in /etc/systemd/system/ in order to automatically launch the service :
    ifconfig.socket (see example file)
    ifconfig.service (see example file)
  • Then execute systemctl daemon-reload and systemctl start ifconfig.socket

Inspired by ifconfig.me, but designed for pure speed. A single server can do 18,000 requests per seconds while only consuming 50megs of ram.

I used the gin framework as it does several things to ensure that there are no memory allocations on each request, keeping the GC happy and preventing unnessary allocations.

Tested to handle 15,000 requests persecond on modest hardware with an adverage response time of 130ms. LoadTest

About

What is my ip address ? ifconfig.me alternative

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 59.7%
  • HTML 40.3%