python 实现 Struct2 探测工具

Structs2探测原理

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

原理说明

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

知识点(Python 3.6.1 版本)

  1. urllib.request 的使用
  2. 日志存储读取
  3. 入参分析

开发环境

Windows7 + Python3.6.1

xiaoqingwang dreamstone_xiaoqw@163.com

"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('<Key-Return>', self.checkURL)
    
def checkURL(self, event):
    self.url = self.contents.get()
    print(self.url)
    checkStructs2(self.url)
    

def checkStructs2(url):

print("<URL> -->", 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('<!DOCTYPE', 0))
res = text.find('<!DOCTYPE', 0)
if res > -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 <Enter> !")
    root.mainloop()

测试结果

遗留问题

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

版权声明

弈心博客


本文首发site_name,转载请附上博文链接!