Skip to content

Instantly share code, notes, and snippets.

@yo-bur
Last active January 12, 2019 03:17
Show Gist options
  • Select an option

  • Save yo-bur/5fcc9e94380c002a36e41b0e04f9cd1b to your computer and use it in GitHub Desktop.

Select an option

Save yo-bur/5fcc9e94380c002a36e41b0e04f9cd1b to your computer and use it in GitHub Desktop.
Spawn a HTTP endpoint that returns the IP address of the connecting request.
# Spawn a HTTP endpoint "/ip" that returns the IP address of the connecting
# request. Requires flask.
HOST = "0.0.0.0"
PORT = 7000
METHODS = ["GET"]
# -- nothing configurable below here -- #
from flask import request
from flask import jsonify, Flask
app = Flask(__name__)
@app.route("/ip", methods=METHODS)
def get_my_ip():
return jsonify({'ip': request.remote_addr}), 200
app.run(host=HOST, port=PORT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment