commit cd18463a8c67599776582690e5e802e0021d68c2 Author: fengbh <1953356163@qq.com> Date: Mon Dec 9 14:58:09 2024 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8991d24 --- /dev/null +++ b/.gitignore @@ -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/ diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000..f57d6e3 --- /dev/null +++ b/ReadMe.md @@ -0,0 +1,11 @@ +# script work + +script work是一系列自己编选的脚本合集。 + +## 项目列表 + +| 项目 | 描述 | 状态 | 备注 | +| ---------------------------------------------- | ----------------------------------------------------- | ---- | ---- | +| [me241200_zerotierApi](./me241200_zerotierApi) | 使用zerotier的api获取网络信息,生成smartdns的配置文件 | 100% | | +| | | | | + diff --git a/me241200_zerotierApi/ReadMe.md b/me241200_zerotierApi/ReadMe.md new file mode 100644 index 0000000..7ac9195 --- /dev/null +++ b/me241200_zerotierApi/ReadMe.md @@ -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`。 + + + diff --git a/me241200_zerotierApi/main.py b/me241200_zerotierApi/main.py new file mode 100644 index 0000000..6ce9f08 --- /dev/null +++ b/me241200_zerotierApi/main.py @@ -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") \ No newline at end of file diff --git a/me241200_zerotierApi/requirements.txt b/me241200_zerotierApi/requirements.txt new file mode 100644 index 0000000..fefd679 --- /dev/null +++ b/me241200_zerotierApi/requirements.txt @@ -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 diff --git a/me241200_zerotierApi/smartdns.conf b/me241200_zerotierApi/smartdns.conf new file mode 100644 index 0000000..0c47eac --- /dev/null +++ b/me241200_zerotierApi/smartdns.conf @@ -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