【Python】Struct2 探测工具

Structs2探测原理

http://mp.weixin.qq.com/s/EhBNkBdVEUm4P7KAwwrlpA


原理说明

探测的原理是打开网页,分析返回结果是否正常


知识点(Python 3.6.1 版本)

1. urllib.request 的使用

2. 日志存储读取

3. 入参分析


开发环境

Windows7 + Python3.6.1

#xiaoqingwang [email protected]
"For check server use structs"
import urllib.request
import sys
# coding=utf-8
from tkinter import *

class getMsgURL(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.entrythingy = Entry(self, width = 58)
        self.entrythingy.pack()
        self.contents = StringVar()
        self.entrythingy.config(textvariable=self.contents)
        self.entrythingy.bind('', self.checkURL)
        
    def checkURL(self, event):
        self.url = self.contents.get()
        print(self.url)
        checkStructs2(self.url)
        
def checkStructs2(url):
    print(" -->", url)
    request = urllib.request.Request(url)
    try:response = urllib.request.urlopen(request)
    except Exception as e:
        print(e)
        return 0
    data = response.read()
    datautf = data.decode('UTF-8')
    fo = open('log.html', 'w',encoding='utf-8')
    fo.write(datautf)
    fo.close()
    text = open('log.html', encoding='utf8').read() 
    #print(text.encode('utf8'))
    print(text.find(' -1:
        print('not use structs2')
    else:
        print('use structs2')
    fo.close() 
        
if __name__ == "__main__":
    url = "http://www.youku.com"
    if len(sys.argv)== 2:
        url = sys.argv[1]
        checkStructs2(url);
        print(url)
    else:
        root = getMsgURL()
        root.master.title("-> Please Input URL and Press  !")
        root.mainloop()

测试结果

【Python】Struct2 探测工具_第1张图片


遗留问题

待分析的URL没有做处理,不过对于本工具的开发来说,已经不是问题。字符串拼接就可以。


你可能感兴趣的:(模块开发)