护网IP去重,去白名单

import csv

from tkinter import *

from tkinter import ttk

from tkinter.messagebox import showinfo, askyesno

从文件中读取IP列表并查询

def read_ip_list():

ip_list = []

with open('ip_list.txt', 'r') as file:

for line in file:

ip = line.strip()

if not search_ip(ip):

ip_list.append(ip)

print(ip)

store_ip_list(ip_list)

showinfo("完成", "成功处理IP列表")

查询IP是否存在于库中

def search_ip(ip):

with open('ip_database.csv', 'r') as file:

reader = csv.reader(file)

for row in reader:

if row[0] == ip:

return True

return False

存储IP列表到库中

def store_ip_list(ip_list):

with open('ip_database.csv', 'a', newline='') as file:

writer = csv.writer(file)

for ip in ip_list:

writer.writerow([ip])

单个IP查询

def search_single_ip():

ip = entry.get()

if search_ip(ip):

showinfo("Result", f"IP {ip} exists in the database")

else:

showinfo("Result", f"IP {ip} does not exist in the database")

删除单个IP

def delete_single_ip():

ip = entry.get()

if search_ip(ip):

confirmation = askyesno("Confirmation", f"Are you sure you want to delete IP {ip}?")

if confirmation:

with open('ip_database.csv', 'r') as file:

lines = file.readlines()

with open('ip_database.csv', 'w') as file:

for line in lines:

if line.strip() != ip:

file.write(line)

showinfo("Success", f"IP {ip} has been deleted from the database")

else:

showinfo("Error", f"IP {ip} does not exist in the database")

创建图形化界面

window = Tk()

window.title("IP去重工具")

window.geometry("500x400")

创建标题标签

title_label = ttk.Label(window, text="IP去重工具", font=("Helvetica", 16))

title_label.pack(pady=10)

创建按钮框架

button_frame = Frame(window)

button_frame.pack(pady=10)

read_button = ttk.Button(button_frame, text="读取IP列表", command=read_ip_list)

read_button.grid(row=0, column=1, padx=5)

创建输入框和按钮框架

input_frame = Frame(window)

input_frame.pack(pady=10)

entry = ttk.Entry(input_frame)

entry.grid(row=0, column=0, padx=5)

search_button = ttk.Button(input_frame, text="单个查询IP", command=search_single_ip)

search_button.grid(row=0, column=1, padx=5)

delete_button = ttk.Button(input_frame, text="删除单个IP", command=delete_single_ip)

delete_button.grid(row=0, column=2, padx=5)

创建状态标签

status_label = ttk.Label(window, text="")

status_label.pack(pady=10)

window.mainloop()

相关推荐
wmm_会飞的@鱼5 分钟前
FlexSim-汽车零部件仓库布局优化与仿真
服务器·前端·网络·数据库·数学建模·汽车
Antonio9158 分钟前
【Redis】Redis 数据存储原理和结构
数据库·redis·缓存
看天走路吃雪糕30 分钟前
墨者:SQL手工注入漏洞测试(MySQL数据库)
数据库·mysql·sql注入·墨者靶场
看天走路吃雪糕39 分钟前
墨者:通过手工解决SQL手工注入漏洞测试(PostgreSQL数据库)
数据库·sql·postgresql·sql注入·墨者靶场
程序员编程指南1 小时前
Qt 与 WebService 交互开发
c语言·开发语言·c++·qt·交互
看天走路吃雪糕1 小时前
墨者:SQL注入漏洞测试(布尔盲注)
数据库·sql·sqlmap·墨者学院·布尔盲注
*愿风载尘*1 小时前
ksql连接数据库免输入密码交互
数据库·后端
追风少年浪子彦1 小时前
mybatis-plus实体类主键生成策略
java·数据库·spring·mybatis·mybatis-plus
赵英英俊1 小时前
Python day26
开发语言·python
你怎么知道我是队长1 小时前
python---eval函数
开发语言·javascript·python