python flask查找ip

operate_ip = request.headers.get('X-Forwarded-For')
if operate_ip:
operate_ip = operate_ip.split(',')[0]
if not operate_ip:
try:
operate_ip = request.remote_addr
except Exception as e:
print(e)
operate_ip = '0.0.0.0'
posted @ 2021-07-27 16:12  wyz_1  阅读(104)  评论(0编辑  收藏  举报