This commit is contained in:
fengbh 2024-12-09 14:58:09 +08:00
commit cd18463a8c
6 changed files with 83 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
0_sv_learn
1_bash_learn
2_dpi
3_python_learn
4_c_re
5_vpi
sv_lab
.vscode/
me241200_zerotierApi/env/

11
ReadMe.md Normal file
View File

@ -0,0 +1,11 @@
# script work
script work是一系列自己编选的脚本合集。
## 项目列表
| 项目 | 描述 | 状态 | 备注 |
| ---------------------------------------------- | ----------------------------------------------------- | ---- | ---- |
| [me241200_zerotierApi](./me241200_zerotierApi) | 使用zerotier的api获取网络信息生成smartdns的配置文件 | 100% | |
| | | | |

View File

@ -0,0 +1,26 @@
# zerotierApi
## 概述
使用python调用zerotier的api获取整个网络的节点信息。进而生成smartdns需要的配置文件。
## 快速开始
### 一、配置环境
```bash
python3 -m venv env
source ./env/bin/activate
pip install -r requirements.txt
```
### 二、运行程序
```bash
python main.py
```
打印当前网络的节点信息,并在当前目录下产生文件`smartdns.conf`

View File

@ -0,0 +1,19 @@
import requests
import json
headers={
'Authorization': 'token UPmCF82KqqqWghdlnhfUaQ4Kp24c6qth'
}
url=' https://api.zerotier.com/api/v1/network/af78bf94361850a3/member'
param = {}
response = requests.get(url=url,params=param,headers=headers) #三个参数
memberData = json.loads(response.text)
with open("smartdns.conf", '+w') as f:
f.write(f"bind [::]:53\n")
f.write(f"server 192.168.3.1\n")
f.write(f"server 223.5.5.5\n")
for i in memberData:
config=i['config']
print(f"id: {config['id']};\tname: {i['name']};\tdescription: {i['description']};\tip: {config['ipAssignments']}")
f.write(f"address /{i['name']}.fbh/{','.join(config['ipAssignments'])}\n")

View File

@ -0,0 +1,6 @@
certifi==2024.8.30
charset-normalizer==2.0.12
idna==3.10
pkg-resources==0.0.0
requests==2.27.1
urllib3==1.26.20

View File

@ -0,0 +1,12 @@
bind [::]:53
server 192.168.3.1
server 223.5.5.5
address /main.fbh/192.168.193.24
address /fby.fbh/192.168.193.102
address /home.fbh/192.168.193.224
address /bak.fbh/192.168.193.36
address /test.fbh/192.168.193.14
address /gs.fbh/192.168.193.101
address /tg.fbh/192.168.193.37
address /phone.fbh/192.168.193.193
address /nas.fbh/192.168.193.7