使用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 从远程服务器下载日志文件的程序
Feb 10 Python
在Python中处理列表之reverse()方法的使用教程
May 21 Python
Python采用Django开发自己的博客系统
Sep 29 Python
python使用pyqt写带界面工具的示例代码
Oct 23 Python
在python中pandas读文件,有中文字符的方法
Dec 12 Python
Django 对象关系映射(ORM)源码详解
Aug 06 Python
python数组循环处理方法
Aug 26 Python
详解使用django-mama-cas快速搭建CAS服务的实现
Oct 30 Python
tensorflow 获取checkpoint中的变量列表实例
Feb 11 Python
python 利用 PIL 将数组值转成图片的实现
Apr 12 Python
Python图片检索之以图搜图
May 31 Python
还在手动盖楼抽奖?教你用Python实现自动评论盖楼抽奖(一)
Jun 07 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 syntax error, unexpected $end 错误的一种原因及解决
2008/10/25 PHP
PHP和javascript常用正则表达式及用法实例
2014/07/01 PHP
smarty模板引擎从php中获取数据的方法
2015/01/22 PHP
php读取文件内容的方法汇总
2015/01/24 PHP
php函数实现判断是否移动端访问
2015/03/03 PHP
php函数连续调用实例分析
2015/07/30 PHP
优化javascript的执行速度
2010/01/23 Javascript
jQuery的实现原理的模拟代码 -2 数据部分
2010/08/01 Javascript
javascript 得到文件后缀名的思路及实现
2020/05/09 Javascript
JavaScript Ajax Json实现上下级下拉框联动效果实例代码
2013/11/23 Javascript
jQuery源码解读之removeAttr()方法分析
2015/02/20 Javascript
通过伪协议解决父页面与iframe页面通信的问题
2015/04/05 Javascript
基于javascript实现随机颜色变化效果
2016/01/14 Javascript
Nodejs--post的公式详解
2017/04/29 NodeJs
关于vue.js组件数据流的问题
2017/07/26 Javascript
vue里如何主动销毁keep-alive缓存的组件
2019/03/21 Javascript
[05:26]2014DOTA2西雅图国际邀请赛 iG战队巡礼
2014/07/07 DOTA
Python实现将n个点均匀地分布在球面上的方法
2015/03/12 Python
python统计字符串中指定字符出现次数的方法
2015/04/04 Python
浅析Python中的join()方法的使用
2015/05/19 Python
使用Django Form解决表单数据无法动态刷新的两种方法
2017/07/14 Python
Django学习教程之静态文件的调用详解
2018/05/08 Python
python os.listdir按文件存取时间顺序列出目录的实例
2018/10/21 Python
python2与python3中关于对NaN类型数据的判断和转换方法
2018/10/30 Python
python判断列表的连续数字范围并分块的方法
2018/11/16 Python
Python 解决火狐浏览器不弹出下载框直接下载的问题
2020/03/09 Python
eBay爱尔兰站:eBay.ie
2019/08/09 全球购物
abstract class和interface有什么区别?
2012/01/03 面试题
几个常见的消息中间件(MOM)
2014/01/08 面试题
观看《永远的雷锋》心得体会
2014/03/12 职场文书
含预算的公司户外活动方案
2014/08/16 职场文书
拾金不昧表扬信
2015/01/16 职场文书
八一建军节主持词
2015/07/01 职场文书
新娘婚礼答谢词
2015/09/29 职场文书
MySQL笔记 —SQL运算符
2022/01/18 MySQL
MySQL如何快速创建800w条测试数据表
2022/03/17 MySQL