护网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()

相关推荐
王者鳜錸1 小时前
PYTHON让繁琐的工作自动化-PYTHON基础
python·microsoft·自动化
key_Go1 小时前
7.Ansible自动化之-实施任务控制
python·ansible·numpy
星霜笔记3 小时前
Docker 部署 MariaDB+phpMyAdmin+Nextcloud 完整教程
运维·数据库·docker·容器·mariadb
阿珊和她的猫4 小时前
v-scale-scree: 根据屏幕尺寸缩放内容
开发语言·前端·javascript
fouryears_234176 小时前
Flutter InheritedWidget 详解:从生命周期到数据流动的完整解析
开发语言·flutter·客户端·dart
我好喜欢你~7 小时前
C#---StopWatch类
开发语言·c#
lifallen8 小时前
Java Stream sort算子实现:SortedOps
java·开发语言
IT毕设实战小研8 小时前
基于Spring Boot 4s店车辆管理系统 租车管理系统 停车位管理系统 智慧车辆管理系统
java·开发语言·spring boot·后端·spring·毕业设计·课程设计
wyiyiyi9 小时前
【Web后端】Django、flask及其场景——以构建系统原型为例
前端·数据库·后端·python·django·flask
mit6.8249 小时前
[1Prompt1Story] 滑动窗口机制 | 图像生成管线 | VAE变分自编码器 | UNet去噪神经网络
人工智能·python