-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPI.py
37 lines (30 loc) · 1.11 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
import requests
import json
api_url = "http://127.0.0.1:7655/api/"
auth_code = "test" # 验证码
# 添加端口映射
def add_mapping(listen_addr, forward_addr):
headers = {"Authorization": auth_code}
data = {"listenAddr": listen_addr, "forwardAddr": forward_addr, "mappingType" : "tcp"}
response = requests.post(api_url + "add", json=data, headers=headers)
print(response.status_code)
print(response.text)
# 删除端口映射
def delete_mapping(listen_addr):
headers = {"Authorization": auth_code}
params = {"listenAddr": listen_addr, "mappingType": "tcpudp"}
response = requests.delete(api_url + "delete", params=params, headers=headers)
print(response.status_code)
print(response.text)
# 查询端口映射
def query_mappings():
headers = {"Authorization": auth_code}
response = requests.get(api_url + "query", headers=headers)
print(response.status_code)
print(response.text)
# delete_mapping(":90")
add_mapping(":80", "192.168.8.1:80")
add_mapping(":81", "192.168.8.1:81")
add_mapping(":82", "192.168.8.1:82")
add_mapping(":83", "192.168.8.1:8")
query_mappings()