-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.py
More file actions
48 lines (48 loc) · 1.61 KB
/
api.py
File metadata and controls
48 lines (48 loc) · 1.61 KB
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
import requests,json,sys
def get_file(file):
with open(file, 'r') as theFile:
content = theFile.read()
return content
URL_API = 'https://sv1.smproxy.net/apit/'
class Api():
def __init__(self):
self.list_key = get_file('key.txt').splitlines()
self.list_ip = get_file('ip_set.txt').splitlines()
def set_ip_allow(self,ip):
data = {}
data['data'] = [{'key':key,'ip':ip} for key in self.list_key]
return self.post('set_ip_allow',data)
def set_listip_allow(self):
data,p = {},[]
if len(self.list_key) == len(self.list_ip):
for i,key in enumerate(self.list_key):
p.append({'key':key,'ip':self.list_ip[i]})
data['data'] = p
s = self.post('set_ip_allow',data)
else:
s = '{"message":"list ip and list key not equal"}'
return s
def info_proxy(self):
data = {}
data['key'] = self.list_key
return self.post('info_proxy',data)
def renew_ip(self):
data = {}
data['key'] = self.list_key
return self.post('renew_ip',data)
def post(self,path,data):
r = requests.post('{url}{path}'.format(url=URL_API,path=path),data=json.dumps(data))
s = r.text if r.status_code == 200 else '{"message":"error request"}'
return s
tinhnang = sys.argv[1]
if tinhnang == 'set_ip':
d = Api().set_ip_allow(sys.argv[2])
elif tinhnang == 'set_listip':
d = Api().set_listip_allow()
elif tinhnang == 'info_proxy':
d = Api().info_proxy()
elif tinhnang == 'renew_ip':
d = Api().renew_ip()
else:
d = 'not found'
print(d)