Get v0.3 from http_banner in section C

Source: Internet
Author: User

Get v0.3 from http_banner in section C
Update: 1. Use optparse to obtain command line parameters

#-*-Coding = UTF-8-*-# _ author _ = 'sanr' # _ email _ = '2017 @ qq.com '# _ url _ =' http://0x007.blog.51cto.com/ '# _ Version _ =' 0. 3 'import requestsimport refrom threading import Thread, Lockimport sysimport chardetimport netaddrimport structimport socketimport osimport optparselock = Lock () def ip2int (addr): return struct. unpack ("! I ", socket. inet_aton (addr) [0] def int2ip (addr): return socket. inet_ntoa (struct. pack ("! I ", addr) def int_dec (pagehtml): charset = None if pagehtml! = '': # Print 'use charset dect 'enc = chardet. detect (pagehtml) # print 'enc = ', enc if enc ['encoding'] and enc ['confidence']> 0.9: charset = enc ['encoding'] if charset = None: charset_re = re. compile ("(^ |;) \ s * charset \ s * =) ([^ \" '] *) ", re. m) charset = charset_re.search (pagehtml [: 1000]) charset = charset and charset. group (3) or None # test charset try: if charset: unicode ('test', charset, errors = 'replace ') Failed t Exception, e: print 'exception', e charset = None # print 'charset =', charset return charsetdef http_banner (url): ip = url try: url = requests. get (url, timeout = 2) body = url. content charset = None if body! = '': Charset = int_dec (body) if charset = None or charset = 'ascii ': charset = 'iso-8859-1' if charset and charset! = 'Ascii 'and charset! = 'Unicode ': try: body = unicode (body, charset, errors = 'replace') except t Exception, e: body = ''Struts = url. status_code Server = url. headers ['server'] [] if Struts = 200 or Struts = 403 or Struts = 401: title = re. findall (r "<title> (. *) <\/title> ", body) if len (title): title = title [0]. strip () else: title = ''# output lock to prevent second row input # apply for lock. acquire () print ('% s \ t % d \ t %-10s \ t % s' % (ip. lstrip ('HTTP: // '), Struts, Server, title) # Release lock. release () doesn t (requests. HTTPError, requests. requestException, AttributeError, KeyError), e: pass

 

If _ name _ = '_ main _': parser = optparse. optionParser ('usage: % prog [options] target') parser. add_option ('-p',' -- port', dest = 'Port', default = '80', type = 'string', help = 'port. default = 80') (options, args) = parser. parse_args () # parser. after parse_args is processed, a dictionary object is returned for option. The key of the object is the value of dest you set above.
   if len(args) < 1:        parser.print_help()        print 'usage: python %s 218.92.227.1/24 '%os.path.basename(sys.argv[0])        print 'usage: python %s 218.92.227.1-218.92.227.254 '%os.path.basename(sys.argv[0])        print 'usage: python %s 218.92.227.1./24 -p 8080'%os.path.basename(sys.argv[0])        print 'usage: python %s 218.92.227.1-218.92.227.254 -p 8080'%os.path.basename(sys.argv[0])        sys.exit(0)             ips=args[0]    port=options.port    if '-' in ips:        start, end = ips.split('-')        startlong = ip2int(start)        endlong = ip2int(end)        ips = netaddr.IPRange(start,end)        for ip in list(ips):            url='http://%s:%s'%(ip,port)            t = Thread(target=http_banner,args=(url,))            t.daemon=False            t.start()    elif '/'   in ips:        ips = netaddr.IPNetwork(ips)        for ip in list(ips):            url='http://%s:%s'%(ip,port)             t = Thread(target=http_banner,args=(url,))            t.daemon=False            t.start()

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.