使用Python制作获取网站目录的图形化程序


Posted in Python onMay 04, 2015

1.pyqt4写的界面 find_ui.py

#-*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
 
try:
  _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
  def _fromUtf8(s):
    return s
 
try:
  _encoding = QtGui.QApplication.UnicodeUTF8
  def _translate(context, text, disambig):
    return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
  def _translate(context, text, disambig):
    return QtGui.QApplication.translate(context, text, disambig)
 
class Ui_Form(object):
  def setupUi(self, Form):
    Form.setObjectName(_fromUtf8("Form"))
    Form.resize(516, 467)
    self.label = QtGui.QLabel(Form)
    self.label.setGeometry(QtCore.QRect(20, 10, 54, 16))
    self.label.setObjectName(_fromUtf8("label"))
    self.edit_address = QtGui.QLineEdit(Form)
    self.edit_address.setGeometry(QtCore.QRect(80, 10, 351, 20))
    self.edit_address.setObjectName(_fromUtf8("edit_address"))
    self.button_search = QtGui.QPushButton(Form)
    self.button_search.setGeometry(QtCore.QRect(440, 10, 61, 23))
    self.button_search.setObjectName(_fromUtf8("button_search"))
    self.text_all = QtGui.QTextEdit(Form)
    self.text_all.setGeometry(QtCore.QRect(20, 40, 411, 261))
    self.text_all.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
    self.text_all.setObjectName(_fromUtf8("text_all"))
    self.label_2 = QtGui.QLabel(Form)
    self.label_2.setGeometry(QtCore.QRect(20, 320, 54, 12))
    self.label_2.setObjectName(_fromUtf8("label_2"))
    self.text_exist = QtGui.QTextEdit(Form)
    self.text_exist.setGeometry(QtCore.QRect(20, 340, 411, 64))
    self.text_exist.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
    self.text_exist.setObjectName(_fromUtf8("text_exist"))
    self.label_3 = QtGui.QLabel(Form)
    self.label_3.setGeometry(QtCore.QRect(380, 310, 91, 20))
    self.label_3.setText(_fromUtf8(""))
    self.label_3.setObjectName(_fromUtf8("label_3"))
    self.edit_add = QtGui.QLineEdit(Form)
    self.edit_add.setGeometry(QtCore.QRect(20, 420, 411, 20))
    self.edit_add.setObjectName(_fromUtf8("edit_add"))
    self.button_add = QtGui.QPushButton(Form)
    self.button_add.setGeometry(QtCore.QRect(440, 420, 71, 23))
    self.button_add.setObjectName(_fromUtf8("button_add"))
    self.label_4 = QtGui.QLabel(Form)
    self.label_4.setGeometry(QtCore.QRect(20, 440, 251, 16))
    self.label_4.setObjectName(_fromUtf8("label_4"))
 
    self.retranslateUi(Form)
    QtCore.QMetaObject.connectSlotsByName(Form)
 
  def retranslateUi(self, Form):
    Form.setWindowTitle(_translate("Form", "目录探测工具", None))
    self.label.setText(_translate("Form", "网站地址:", None))
    self.button_search.setText(_translate("Form", "探测", None))
    self.label_2.setText(_translate("Form", "结果:", None))
    self.button_add.setText(_translate("Form", "添加地址", None))
    self.label_4.setText(_translate("Form", "例如:/admin/manager.asp 请以斜杠开始", None))

2. 启动文件 start.py

#!/usr/local/bin/python
#coding=utf-8
 
import sys
import os
import time
import httplib
import re
from PyQt4 import QtCore, QtGui
from threading import Thread
 
from find_ui import Ui_Form
 
 
class MyForm(QtGui.QMainWindow):
  def __init__(self, parent=None):
    QtGui.QWidget.__init__(self, parent)
    self.ui = Ui_Form()
    self.ui.setupUi(self)
    QtCore.QObject.connect(self.ui.button_search,QtCore.SIGNAL("clicked()"), self.startthread)
    QtCore.QObject.connect(self.ui.button_add,QtCore.SIGNAL("clicked()"), self.addAddress)
  def startSearch(self):
    self.ui.label_3.setText("")
    self.getAddress()
    address=str(self.ui.edit_address.text())
    self.accessAddesss(address)
     
  def startthread(self):
    t1=Thread(target=self.startSearch,)
    t1.start()
     
     
  def getAddress(self):
    try:
      global addresslist
      addresslist=[]
      filePath=os.getcwd()+"\\address.txt"
      # if not os.path.isfile(filePath):
      #  print 'aaa'      
       #  return 0
         
      fileAddress=file(filePath,"r")
      for address_line in fileAddress.readlines():
        if address_line not in addresslist:
          addresslist.append(address_line)
          pass
        pass
      pass
      fileAddress.close()
       
    except:
      #self.ui.text_all.setText('aaa')
      self.ui.text_all.setText(u'打开文件错误')
      pass
    finally:
      #fileAddress.close()
      pass
    # print addresslist[0]
   
  def accessAddesss(self,host):
    try:
      print host
      print len(addresslist)
      for oneAddress in addresslist:
        print len(addresslist)
        oneAddress=oneAddress.replace("\n","")
        print oneAddress
        connection=httplib.HTTPConnection(host,80,timeout=10)
        connection.request("GET",oneAddress)
        response=connection.getresponse()
        result=response.reason
        resultNum=response.status
         
        if "OK" in result or "Forbidden" in result:
          getaddress="http://"+host+oneAddress+"------"+str(resultNum)+":"+result
          self.ui.text_exist.append(getaddress)
        else:
          self.ui.text_all.append("http://"+host+oneAddress+"------"+str(resultNum)+":"+result)
           
        connection.close()
    except Exception as e:
      print e.message
    self.ui.label_3.setText(u"探测完成")
    self.ui.label_3.colorCount()
     
  def addAddress(self):
    try:
      filePath=os.getcwd()+"\\address.txt"   
      fileAddress=file(filePath,"a")
      newAddress="\n"+str(self.ui.edit_add.text())
      print newAddress
      fileAddress.write(newAddress)
      fileAddress.close()
    except Exception as e:
      print e.message
     
 
if __name__ == "__main__":
  app = QtGui.QApplication(sys.argv)
  myapp = MyForm()
  myapp.show()
  sys.exit(app.exec_())

3.address.txt 扫描地址名单文件,可以通过编辑改文件制定自己的规则,你懂的~~

/admin.php
/admin/
/administrator/
/moderator/
/webadmin/
/adminarea/
/bb-admin/
/adminLogin/
/test/login.jsp
/source/login.php
Python 相关文章推荐
跟老齐学Python之集成开发环境(IDE)
Sep 12 Python
Python多线程编程(一):threading模块综述
Apr 05 Python
Python 处理数据的实例详解
Aug 10 Python
Python中input与raw_input 之间的比较
Aug 20 Python
dataframe设置两个条件取值的实例
Apr 12 Python
win10系统下Anaconda3安装配置方法图文教程
Sep 19 Python
Python数据类型之列表和元组的方法实例详解
Jul 08 Python
Python3.7黑帽编程之病毒篇(基础篇)
Feb 04 Python
python3+opencv生成不规则黑白mask实例
Feb 19 Python
如何写python的配置文件
Jun 07 Python
为什么相对PHP黑python的更少
Jun 21 Python
无惧面试,带你搞懂python 装饰器
Aug 17 Python
使用Python脚本来获取Cisco设备信息的示例
May 04 #Python
用Python脚本来删除指定容量以上的文件的教程
May 04 #Python
编写Python脚本来获取Google搜索结果的示例
May 04 #Python
编写Python脚本来实现最简单的FTP下载的教程
May 04 #Python
Python下线程之间的共享和释放示例
May 04 #Python
简单介绍Python中利用生成器实现的并发编程
May 04 #Python
简单分析Python中用fork()函数生成的子进程
May 04 #Python
You might like
PHP/ThinkPHP实现批量打包下载文件的方法示例
2017/07/31 PHP
PHP使用PDO访问oracle数据库的步骤详解
2017/09/29 PHP
dojo 之基础篇(三)之向服务器发送数据
2007/03/24 Javascript
jquery 1.4.2发布!主要是性能与API
2010/02/25 Javascript
ASP.NET中基于JQUERY的高性能的TreeView补充
2011/02/23 Javascript
淘宝搜索框效果实现分析
2011/03/05 Javascript
不提示直接关闭网页窗口的JS示例代码
2013/12/17 Javascript
jquery序列化表单去除指定元素示例代码
2014/04/10 Javascript
JavaScript实现的一个日期格式化函数分享
2014/12/06 Javascript
Javascript无参数和有参数类继承问题解决方法
2015/03/02 Javascript
通过实例理解javascript中没有函数重载的概念
2015/06/03 Javascript
javascript实现延时显示提示框特效代码
2016/04/27 Javascript
微信JS SDK接入的几点注意事项(必看篇)
2017/06/23 Javascript
Vue 仿QQ左滑删除组件功能
2018/03/12 Javascript
详解element-ui级联菜单(城市三级联动菜单)和回显问题
2019/10/02 Javascript
js+html+css实现手动轮播和自动轮播
2020/12/30 Javascript
[02:46]2014DOTA2国际邀请赛 选手为你解读比赛MVP充满梦想
2014/07/09 DOTA
可用于监控 mysql Master Slave 状态的python代码
2013/02/10 Python
在Python中使用Mako模版库的简单教程
2015/04/08 Python
使用Python的web.py框架实现类似Django的ORM查询的教程
2015/05/02 Python
详解Python读取配置文件模块ConfigParser
2017/05/11 Python
python爬虫中get和post方法介绍以及cookie作用
2018/02/08 Python
keras中模型训练class_weight,sample_weight区别说明
2020/05/23 Python
详解Django中异步任务之django-celery
2020/11/05 Python
Python抖音快手代码舞(字符舞)的实现方法
2021/02/07 Python
使用HTML5 Canvas绘制直线或折线等线条的方法讲解
2016/03/14 HTML / CSS
后备干部考察材料
2014/02/12 职场文书
校园联欢晚会主持词
2014/03/17 职场文书
军训拉歌口号
2014/06/13 职场文书
2014年人事部工作总结
2014/12/03 职场文书
2015年感恩节演讲稿(优选篇)
2015/03/20 职场文书
MBA推荐信怎么写
2015/03/25 职场文书
休假证明书
2015/06/24 职场文书
围城读书笔记
2015/06/26 职场文书
初中毕业感言300字
2015/07/31 职场文书
从np.random.normal()到正态分布的拟合操作
2021/06/02 Python