import socket import time # 定义要查询的域名和初始IP地址 hostname = 'c27s3.jamjams.net' ip_address = None while True: # 获取当前的IP地址 new_ip_address = socket.gethostbyname(hostname) # 判断IP地址是否发生变化 if new_ip_address != ip_address: if ip_address is not None: print(f"The IP address for {hostname} has changed: {new_ip_address}") else: print(f"Initial IP address for {hostname}: {new_ip_address}") # 更新IP地址 ip_address = new_ip_address # 等待10秒钟 time.sleep(10)