image.png (24.47 KB, 下载次数: 0)
下载附件
2024-1-1 18:47 上传
image.png (33.44 KB, 下载次数: 0)
下载附件
2024-1-1 18:47 上传
[Python] 纯文本查看 复制代码from tkinter import *
from tkinter import ttk
import requests
def query_ip():
ip = entry.get()
if not ip:
# 如果用户没有输入 IP 地址,查询本机公网 IP 地址
response = requests.get('https://api.ipify.org')
if response.status_code == 200:
ip = response.text
entry.delete(0, END)
entry.insert(END, ip)
else:
text.delete(1.0, END)
text.insert(INSERT, '查询失败')
return
url = f'https://wq.apnic.net/apnic-bin/jwhois.pl?ip={ip}'
response = requests.get(url)
if response.status_code == 200:
result = response.text
formatted_result = format_result(result)
text.delete(1.0, END)
text.insert(INSERT, formatted_result)
with open(f'{ip}.log', 'w') as f:
f.write(f'查询IP:{ip}\n查询结果:{formatted_result}\n')
else:
text.delete(1.0, END)
text.insert(INSERT, '查询失败')
def format_result(result):
# 这里需要根据实际的返回结果进行格式化
return result
root = Tk()
root.title('IP信息查询-数据来源APNIC-PoweredBy KGSH')
root.geometry('600x400')
Label(root, text='请输入IP地址或直接默认本机公网IP查询').pack(pady=10)
frame = ttk.Frame(root, padding=(20, 10))
frame.pack(fill=BOTH)
entry = ttk.Entry(frame)
entry.pack(side=LEFT, padx=(0, 10))
# 获取本机公网 IP 地址并设置为输入框的默认值
response = requests.get('https://api.ipify.org')
if response.status_code == 200:
ip = response.text
entry.insert(END, ip)
button = ttk.Button(frame, text='查询', command=query_ip)
button.pack(side=LEFT)
text = Text(root, wrap=WORD, relief=SUNKEN, borderwidth=1)
text.pack(fill=BOTH, padx=20, pady=10)
root.mainloop()
"