Home Python小工具——资产提纯(pyqt初使用)
Post
Cancel

Python小工具——资产提纯(pyqt初使用)

输入内容(文件选择

   

主域名,子域名,IP地址,HTTP/HTTPS

image-20230816112339770

一、环境

安装pyqt

1
pip install PyQt6 pyqt6-tools pyinstaller

qt 设计师路径

1
C:\Program Files\Python39\Lib\site-packages\qt6_applications\Qt\bin\designer.exe

与VB界面类似

image-20230817133651759

二、代码

设计完 ui 之后,命令行输入下面指令

1
2
# designer 转 code
pyuic6 -x .\main.ui -o main.py

ui 代码 与 py 代码对比

image-20230817133852335

给 按钮 绑定事件

1
self.pushButton.clicked.connect(self.gettextedit)

获取输入框的内容

1
data = self.textEdit.toPlainText()

给文本显示框赋值

1
2
data = "hello!"
self.textBrowser_2.setPlainText(data)

如下面图片

image-20230817134340317

核心代码

显示匹配ip,后在处理 url 提取域名并去重等。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def chuli(data):

    ip_pattern = r'\b(?:\d{1,3}\.){3}\d{1,3}\b'
    ip_addresses = re.findall(ip_pattern, data)

    data_list = list(data.split('\n'))

    top_list = []
    sub_list = []
    for url in data_list:
        domain = tldextract.extract(url)
        if domain.registered_domain != "":
            top_list.append(domain.registered_domain)
            # print(domain.registered_domain)
        if domain.subdomain != "":
            subdo = domain.subdomain + '.' + domain.domain + '.' + domain.suffix
            sub_list.append(subdo)
            # print(subdo)

    unique_ip_addresses = list(set(ip_addresses))
    unique_root_domains = list(set(top_list))
    unique_domains = list(set(sub_list))


    str_ip = ""
    for i in unique_ip_addresses:
        str_ip += i + "\n"

    str_domains = ""
    for i in unique_domains:
        str_domains += i + "\n"
    
    str_rootdom = ""
    for i in unique_root_domains:
        str_rootdom += i + "\n"

    ui.zhuyum(str_rootdom)
    ui.ziyum(str_domains)
    ui.ipadd(str_ip)

三、打包

1
pyinstaller -F main.py --noconsole -n "资产提纯"

打包完会在dist目录下面

image-20230817134743918

实战效果图(拿到的excel资产一列直接复制进去就行)

image-20230817135017051

This post is licensed under CC BY 4.0 by the author.