操作&&实现:值班人员会将探针识别的威胁IP发出,我们复制对应信息粘贴在第一个文本框后按下吾爱按钮,窗口会呈现对应IP归属地及三家防火墙Huawei、Hillstone、H3C的命令,之后将对应命令通过SSH方式登录去粘贴(当时想过使用netmiko或者paramiko,想了一会还是感觉手动粘贴更放心)
注:这里Hillstone用的blacklist是我们自己做的地址簿然后安全策略做的deny,如果您自己的地址簿是其他名称请对应修改hillstone.insert(tk.INSERT, "config\naddress blacklist\n")的blacklist
gouzi2.gif (1.03 MB, 下载次数: 0)
下载附件
2024-1-23 17:33 上传
微信截图_20240123172326.png (111.01 KB, 下载次数: 0)
下载附件
2024-1-23 17:26 上传
模块
import tkinter as tk
import re
from PIL import Image, ImageTk
import requests
from bs4 import BeautifulSoup
import base64
import io# 窗口
root = tk.Tk()
root.title("封禁IP及其归属地查询")
def center_window(window):
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
window.update_idletasks()
window_width = window.winfo_reqwidth()
window_height = window.winfo_reqheight()
x = (screen_width - window_width) // 2
y = (screen_height - window_height) // 2
window.geometry(f"{window_width}x{window_height}+{x}+{y}")
图片区
base64_strings = {
#logo的base编码,详细代码在txt文件内
"huawei_logo": "",
"hillstone": "",
"h3c_logo": "",
"52pojie": ""
}
def create_image_label(root, photo_base64, row, column, sticky):
base64_strings = base64.b64decode(photo_base64)
image= Image.open(io.BytesIO(base64_strings))
photo = ImageTk.PhotoImage(image)
label = tk.Label(root, image=photo)
label.grid(row=row, column=column, sticky=sticky)
label.photo = photo
按钮触发IP操作
def gettext():
content = huawei.get("1.0", "100.end")
ip = re.findall(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', content)
# 清空所有窗口内容
huawei.delete('1.0', "100.end")
hillstone.delete('1.0', "100.end")
h3c.delete('1.0', "100.end")
belong.delete('1.0', "100.end")
# 输入窗口内容
hillstone.insert(tk.INSERT, "config\naddress blacklist\n")
huawei.insert(tk.INSERT, "sys" + "\n")
h3c.insert(tk.INSERT, "sys" + "\n")
# 窗口文本框获取IP
def get_ip():
url = f"http://www.jsons.cn/ipbatch/"
data = {'txt_ip': ip}
response = requests.post(url, data=data)
if response.status_code == 200:
soup = BeautifulSoup(response.text, "html.parser")
table = soup.find("table", {"class": "table-bordered"})
rows = table.find_all("tr")
for j in range(1, len(rows)):
srcip = rows[j].find_all("td")[0].text.strip()
country = rows[j].find_all("td")[1].text.strip()
province = rows[j].find_all("td")[2].text.strip()
city = rows[j].find_all("td")[3].text.strip()
display = f"{srcip} {country} {province} {city}"
belong.insert(tk.INSERT, display + "\n")
else:
belong.insert(tk.INSERT, "查询失败")
for i in ip:
huawei.insert(tk.INSERT, f"firewall blacklist item source-ip {i}\n")
hillstone.insert(tk.INSERT, f"ip {i}/32\n")
h3c.insert(tk.INSERT, f"blacklist ip {i}\n")
get_ip()
文本框区域
huawei = tk.Text(root, height=20, width=50)
huawei.grid(row=1, column=0)
hillstone = tk.Text(root, height=20, width=50)
hillstone.grid(row=1, column=1)
h3c = tk.Text(root, height=20, width=50)
h3c.grid(row=3, column=0)
belong = tk.Text(root, height=20, width=50)
belong.grid(row=3, column=1)
显示窗口
create_image_label(root, "huawei_logo.png", 0, 0, "w")
create_image_label(root, "hillstone.png", 0, 1, "e")
create_image_label(root, "h3c_logo.png", 2, 0, "w")
create_image_label(root, "52pojie.jpg", 2, 1, "e")
center_window(root)
tk.Button(root, text="吾爱出品-https://www.52pojie.cn/", width=40, height=2 ,command=gettext, bg="#CCCCFF").grid(row=2, column=0, columnspan=2)
root.mainloop()
[最终采用评论老哥@VanYun只把图片进行base64转码来规避这个问题]请教:pyinstaller能否把图片也一起封装单文件内,小弟自己试了几次一直不行,显示找不到我的图片,最后只能把图片跟exe文件放置同目录,如果有大佬知道怎么做到的话,还望指点,谢谢!
源码(lanzou不给传py文件,将txt后缀改为py就可以跑了)下载地址:https://wwd.lanzoul.com/ini1r1mqnpad