import tkinter as tk
import winreg
import ctypes
import kdl
import kdl
import requests
def is_local_ip_in_whitelist(secret_id, signature):
auth = kdl.Auth(secret_id, signature)
client = kdl.Client(auth, timeout=(8, 12), max_retries=3)
获取ip白名单,返回ip列表
ip_whitelist = client.get_ip_whitelist()
print(“ip白名单为”, ip_whitelist)
获取公网IP地址
def get_public_ip():
try:
response = requests.get(“http://httpbin.org/ip”)
data = response.json()
ip = data[‘origin’]
return ip
except Exception as e:
print(f"Error getting public IP: {e}")
return None
local_ip = get_public_ip()
print(“本机IP地址为:”, local_ip)
检查本机IP是否在白名单中
is_ip_in_whitelist = local_ip in ip_whitelist
print(“本地ip是否在白名单中:”, is_ip_in_whitelist)
如果本机IP不在白名单中,设置ip白名单
if not is_ip_in_whitelist:
# 设置ip白名单,参数类型为字符串或列表或元组
client.set_ip_whitelist(local_ip)
# 再次获取ip白名单,返回ip列表
updated_ip_whitelist = client.get_ip_whitelist()
print("ip白名单重置为", updated_ip_whitel