# coding: UTF-8

import sys, os, time, httplib
import re
list_http=[]  #http数组

def open_httptxt():  #打开TXT文本写入数组
    try:
        passlist = []
        list_passlist=[]
        xxx = file('http.txt', 'r')
        for xxx_line in xxx.readlines():
            #past.append(xxx_line)
            passlist.append(xxx_line)
        xxx.close()

        for i in passlist:  #python 列表去重
            if i not in list_passlist:
                list_passlist.append(i)

        E = 0 #得到list的第一个元素
        while E < len(list_passlist):
            #print list_passlist[E]
            past.append(list_passlist[E])  #添加到数组里
            E = E + 1
    except:
        return 0

def pst_http(host):   #获取是否开放  #pst_http("127.0.0.1")
    try:
        for admin in past:
            admin = admin.replace("\n","")
            connection = httplib.HTTPConnection(host,80,timeout=10)
            connection.request("GET",admin)
            response = connection.getresponse()
            #print "%s %s %s" % (admin, response.status, response.reason)
            #/admin-login.php   ,错误404  ,Not Found   /moderator/ 404 File Not Found
            data=response.reason
            if "OK" in data or "Forbidden" in data:
                SQLdata="http://"+host+admin+"---%s %s"%(response.status, response.reason)
                print SQLdata
            else:
                print "http://"+host+admin+"----"+data
            connection.close()
        return 1
    except:
        pass
        return 0

if __name__=='__main__':
    print u"=============python之web路径扫描工具============="
    global  past    #声明全局变量
    past = []
    open_httptxt()  #打开TXT文本写入数组
    pst_http("baidu.com")

posted on 2015-01-02 18:22  milantgh  阅读(2009)  评论(0编辑  收藏  举报