python扫描内网banner信息
小菜自己无聊写着玩,主要纪念以前的逗逼学习,可以改IPy
import mechanize import cookielib import socket import argparse import threading def 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_all def find_position(ip): m = len(ip)-1 while True: if ip[m] == '.': return m+1 break else: m = m-1 def find_title(url): try: global ip,port br = mechanize.Browser() br.set_cookiejar(cookielib.LWPCookieJar()) # Cookie jar br.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"%url pass if __name__ == "__main__": # name = socket.gethostname() # ip = socket.gethostbyname(name) global ip,port,mutex mutex = 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.a port = args.b thread = args.c threads = [] c = findc(ip) for i in c: print i for 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: break t.start() for t in threads: t.join()