httpscan 爬虫扫描小工具

httpscan是一个扫描指定网段的Web主机的小工具端口扫描器不一样,httpscan是以爬虫的方式进行Web主机发现,因此相对来说不容易被防火墙拦截。
httpscan会返回IP http状态码 Web容器版本 以及网站标题。

httpscan 爬虫扫描小工具

  1. Usage:./httpscan IP/CIDR –t threads
  2. Example:./httpscan.py 10.20.30.0/24 –t 10

Git地址:https://github.com/zer0h/httpscan

主要代码

  1. #!/usr/bin/env python
  2. #coding:utf-8
  3. # Author: Zeroh
  4. import re
  5. import sys
  6. import Queue
  7. import threading
  8. import optparse
  9. import requests
  10. from IPy import IP
  11. printLock = threading.Semaphore(1)  #lock Screen print
  12. TimeOut = 5  #request timeout
  13. #User-Agent
  14. header = {'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36','Connection':'close'}
  15. class scan():
  16.   def __init__(self,cidr,threads_num):
  17.     self.threads_num = threads_num
  18.     self.cidr = IP(cidr)
  19.     #build ip queue
  20.     self.IPs = Queue.Queue()
  21.     for ip in self.cidr:
  22.       ip = str(ip)
  23.       self.IPs.put(ip)
  24.   def request(self):
  25.     with threading.Lock():
  26.       while self.IPs.qsize() > 0:
  27.         ip = self.IPs.get()
  28.         try:
  29.           r = requests.Session().get('https://'+str(ip),headers=header,timeout=TimeOut)
  30.           status = r.status_code
  31.           title = re.search(r'<title>(.*)</title>', r.text) #get the title
  32.           if title:
  33.             title = title.group(1).strip().strip("r").strip("n")[:30]
  34.           else:
  35.             title = "None"
  36.           banner = ''
  37.           try:
  38.             banner += r.headers['Server'][:20] #get the server banner
  39.           except:pass
  40.           printLock.acquire()
  41.           print "|%-16s|%-6s|%-20s|%-30s|" % (ip,status,banner,title)
  42.           print "+----------------+------+--------------------+------------------------------+"
  43.           #Save log
  44.           with open("./log/"+self.cidr.strNormal(3)+".log",'a') as f:
  45.             f.write(ip+"n")
  46.         except Exception,e:
  47.           printLock.acquire()
  48.         finally:
  49.           printLock.release()
  50.   #Multi thread
  51.   def run(self):
  52.     for i in range(self.threads_num):
  53.       t = threading.Thread(target=self.request)
  54.       t.start()
  55. if __name__ == "__main__":
  56.   parser = optparse.OptionParser("Usage: %prog [options] target")
  57.   parser.add_option("-t", "--thread", dest = "threads_num",
  58.     default = 1, type = "int",
  59.     help = "[optional]number of  theads,default=10")
  60.   (options, args) = parser.parse_args()
  61.   if len(args) < 1:
  62.     parser.print_help()
  63.     sys.exit(0)
  64.   print "+----------------+------+--------------------+------------------------------+"
  65.   print "|     IP         |Status|       Server       |            Title             |"
  66.   print "+----------------+------+--------------------+------------------------------+"
  67.   s = scan(cidr=args[0],threads_num=options.threads_num)
  68.   s.run()

转载请注明出处:https://stgod.com/363/

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: