python扫描内网banner信息
生活随笔
收集整理的這篇文章主要介紹了
python扫描内网banner信息
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
小菜自己無聊寫著玩,主要紀念以前的逗逼學習,可以改IPy
import mechanize import cookielib import socket import argparse import threadingdef findc(ip):position = find_position(ip)ip_all = []for i in range(1,256):ip1 = ip[:position] + str(i)ip_all.append(ip1)return ip_alldef find_position(ip):m = len(ip)-1while True:if ip[m] == '.':return m+1breakelse:m = m-1def find_title(url):try:global ip,portbr = mechanize.Browser()br.set_cookiejar(cookielib.LWPCookieJar()) # Cookie jarbr.set_handle_equiv(True) # Browser Option # br.set_handle_gzip(True) br.set_handle_redirect(True)br.set_handle_referer(True)br.set_handle_robots(False)br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] br.open(url)t = br.title().decode('utf-8').encode('gb2312')mutex.acquire()print "url: %s-->%s"%(url,t)mutex.release() except:print "this url don't have titile: %s"%urlpassif __name__ == "__main__": # name = socket.gethostname() # ip = socket.gethostbyname(name) global ip,port,mutexmutex = threading.Lock()parser = argparse.ArgumentParser()parser.add_argument("-i","--ip",dest="a", help='the first argument')parser.add_argument("-p","--port",dest="b",default=80, help='the first argument')parser.add_argument("-t","--thread",dest="c",default=10, type=int,help='the first argument')args=parser.parse_args()ip = args.aport = args.bthread = args.cthreads = []c = findc(ip)for i in c:print ifor i in c:url = "http://"+i.strip()+":"+str(port)threads.append(threading.Thread(target=find_title,args=(url,)))for t in threads:while True:if threading.activeCount() < thread:breakt.start()for t in threads:t.join()?
轉(zhuǎn)載于:https://www.cnblogs.com/lly-lly/p/5390908.html
總結
以上是生活随笔為你收集整理的python扫描内网banner信息的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 边工作边刷题:70天一遍leetcode
- 下一篇: 雷军反击董明珠:感觉董总好像认输了似的