-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
78 lines (63 loc) · 2.21 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
# @Time : 2020-12-28 18:08
# @Author : XuGuangJun
# @FileName: api.py
# @Software: PyCharm
from flask import Flask, g, render_template,request
from db import Reids_Client
import json
import re
import requests
"""
没有找到,如何获得访问者的外网ip方法,只能让其手动
"""
app = Flask(__name__)
def get_conn():
if not hasattr(g, 'redis_client'):
g.redis_client = Reids_Client()
return g.redis_client
@app.route('/')
def index():
print('访问者的IP:',request.remote_addr)
print(request.user_agent)
return render_template("index.html", **locals())
@app.route('/proxy_index')
def proxy_index():
return render_template("proxy_index.html", **locals())
@app.route('/add_ip',methods=['GET','POST'])
def add_ip():
data = request.form
ip = data.get('ip')
if type(ip) == str:
if len(ip) < 11:
res = '请输入正确ip地址!'
return render_template("add_ip.html", **locals())
print('成功')
api_url = 'http://wapi.http.linkudp.com/index/index/save_white?neek=253760&appkey=249595af6047611a7f0136c55508857d&white=' +ip
print(api_url)
res = requests.get(url=api_url).text
return render_template("add_ip.html", **locals())
return render_template("add_ip.html", **locals())
@app.route('/get_http')
def get_http():
res = str(get_conn().pop(types='http'))
res = json.loads(re.sub(r"'", '"', res))
res['use_num'] = str(int(res['use_num']) + 1)
get_conn().lput(str(res), types=res['types'])
# return render_template("http_show.html", **locals())
return res
@app.route('/get_https')
def get_https():
res = str(get_conn().pop(types='https'))
res = json.loads(re.sub(r"'", '"', res))
res['use_num'] = str(int(res['use_num']) + 1)
get_conn().lput(str(res), types=res['types'])
# return render_template("https_show.html", **locals())
return res
@app.route('/count')
def count():
http_parameters, https_parameters = get_conn().queue_len()
# ((54, 'http_proxies', 'http'), (56, 'https_proxies', 'https'))
http_proxy_len = http_parameters[0]
https_proxy_len = https_parameters[0]
return render_template('show.html', **locals())