Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Fifconfig: my ifconfig.me ripoff

I used ifconfig.me recently to show my public IP address, and I decided that I could write my own utility for that. I know that in Flask, the request object has all sorts of properties.

So I wrote my own version, which I call Flask-ifconfig, or fifconfig.

I made mine handle the 'Accept' header for json, html, xml, and text. You could also use a parameter, i.e., ?json to force that return type.

You can check out the code at my cgit site.

README for fifconfig

Upstream

gitlab author's git

Features

  • Provide different output type based on Accept header or url parameter. Options include:
  • application/json or ?json
  • text/html or ?html
  • application/xml or ?xml
  • text/plain or ?text
  • Display IP address as viewed by the web server, or else the first entry of HTTP_X_FORWARDED_FOR.

Using fifconfig

Visit the application.

curl -L https://bgstack15.ddns.net/ifconfig/?json | jq

Installing

You can use flask for development, and uwsgi for production.

Instructions

Configure the application with these two files, based on the .example files available in the source code:

  • fifconfig.conf
  • fifconfig.wsgi.ini
Development

Run server in development mode.

FLASK_APP=fifconfig.py FLASK_DEBUG=True flask run --host='0.0.0.0'
Production

Run the server in a full wsgi environment for the cleanup timer to operate.

./fifconfig.bin

The html responses include links to the various single-field pages, unless you add a parameter ?nolinks. These links depend on any reverse-proxy servers adding themselves correctly to header X-Forwarded-For.

Alternatives

This project was a ripoff of love of http://ifconfig.me.

References

  1. flask.Request — Flask API
  2. my stackbin.py project
  3. dicttoxml - PyPI

Comments