flask自动获取IP


使用flask写一个自动获取IP的网站

# -*- encoding:utf-8 -*-
import flask
from urllib import request
html_txt = """
<!DOCTYPE html>
<html>
    <body>
        <h2>身份确认</h2>
        <form method='post'>
        <input type="password" name='passwd' id="input_invisible" placeholder="Password"/>  
        <input type='submit' value='请求获得IP地址' />
        </form>
    </body>
</html>
"""
app = flask.Flask(__name__)
@app.route('/eagleslab.com',methods=['GET','POST'])
def helo():
    if flask.request.method == 'GET':
        return html_txt
    else:
        passwd = 'passwd' in flask.request.form and flask.request.form['passwd']
        if passwd:
            if passwd == 'test':
                response = request.urlopen(r'http://ip.3322.net/')
                page = response.read()
                page = page.decode('utf-8')
                return 'IP地址是:' + page
            else:
                return '密码错误'
        else:
            return '你没有输入密码!'
if __name__ == '__main__':
    app.run(debug=True)

文章作者: AaronXu
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 AaronXu !
评论
  目录