import requests
import json
# 设置 LibreNMS API 认证信息
api_url = "http://10.40.31.253/api/v0/devices"
api_token = "9560e9254e6e48be8826fd77fe5b031b" # 替换为最新的 API Token
headers = {
"Authorization": f"Bearer {api_token}",
"Content-Type": "application/json"
}
# 读取要删除的设备 IP 地址列表 (假设在 devices_to_delete.txt 文件中,每行一个 IP 地址)
with open("cameras-ip_backup.txt", "r") as file:
ip_addresses = [line.strip() for line in file]
# 删除设备的函数
def delete_device(ip):
delete_url = f"{api_url}/{ip}"
try:
response = requests.delete(delete_url, headers=headers)
response_data = response.json()
if response_data.get("status") == "ok":
print(f"设备 {ip} 删除成功!")
else:
print(f"删除设备 {ip} 时出错: {response_data.get('message')}")
except Exception as e:
print(f"请求删除设备 {ip} 时出现错误: {str(e)}")
# 批量删除设备
def delete_devices(ip_list):
for ip in ip_list:
delete_device(ip)
if __name__ == "__main__":
delete_devices(ip_addresses)
将设备IP添加进入 cameras-ip_backup.txt里面,每行一个IP