Tag Archives: Flask ip

Python flash project to obtain the request user IP address addr

Direct deployment of flash on server

import logging
from flask import Flask, render_template, request

# Initialize the Flask application
app = Flask(__name__)

# Default route, print user's IP
@app.route('/')
def index():
	 ip = request.remote_addr
	 logging.debug(ip)
	 return render_template('index.html', user_ip=ip)


if __name__ == '__main__':
	 app.run(host="0.0.0.0", port=80)

Nginx agent in docker and flash in gunicorn

In this case, according to the above code can only get to the server address. You need to use werkzeug.middleware.proxy_ fix

import logging
from flask import Flask, render_template, request
from werkzeug.middleware.proxy_fix import ProxyFix

# Initialize the Flask application
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, num_proxies=1)


# Default route, print user's IP
@app.route('/')
def index():
	 ip = request.remote_addr
	 logging.debug(ip)
	 return render_template('index.html', user_ip=ip)

What can I do if I find IP

Flag gets the user’s IP, queries the user’s login times, and seals the IP