# Path: lib/core/data.py

# 
# Path: lib/core/enums.py
# class TARGET_MODE_STATUS:
#     FILE = 9
#     SINGLE = 8
#     IPMASK = 7
#     RANGE = 6
#     API = 5
# 
# Path: lib/core/settings.py
# ESSENTIAL_MODULE_METHODS = ['poc']
# 
# Path: lib/core/exception.py
# class ToolkitValueException(ToolkitBaseException):
#     pass
# 
# Path: lib/controller/api.py
# def runApi():
#     output = conf.API_OUTPUT
#     dork = conf.API_DORK
#     limit = conf.API_LIMIT
#     logger.info('Activate %s API' % conf.API_MODE)
#     if conf.API_MODE is API_MODE_NAME.ZOOMEYE:
#         anslist = ZoomEyeSearch(query=dork, limit=limit, type=conf.ZOOMEYE_SEARCH_TYPE, offset=conf.API_OFFSET)
#     elif conf.API_MODE is API_MODE_NAME.BAIDU:
#         anslist = BaiduSearch(query=dork, limit=limit, offset=conf.API_OFFSET)
#     else:
#         raise ToolkitValueException('Unknown API mode')
# 
#     tmpIpFile = os.path.join(output, '%s.txt' % (time.strftime('%Y%m%d%H%M%S')))
#     with open(tmpIpFile, 'w') as fp:
#         for each in anslist:
#             if isinstance(each, list):  # for ZoomEye web type
#                 each = each[0]
#             fp.write(each + '\n')
#     return tmpIpFile
# 
# Path: thirdparty/IPy/IPy.py
# MAX_IPV4_ADDRESS = 0xffffffff
# MAX_IPV6_ADDRESS = 0xffffffffffffffffffffffffffffffff
# IPV6_TEST_MAP    = 0xffffffffffffffffffffffff00000000
# IPV6_MAP_MASK    = 0x00000000000000000000ffff00000000
#     INT_TYPES = (int,)
#     STR_TYPES = (str,)
#     INT_TYPES = (int, long)
#     STR_TYPES = (str, unicode)
# class IPint(object):
# class IP(IPint):
# class IPSet(IPSetBaseClass):
#     def __init__(self, data, ipversion=0, make_net=0):
#     def int(self):
#     def version(self):
#     def prefixlen(self):
#     def net(self):
#     def broadcast(self):
#     def _printPrefix(self, want):
#     def strBin(self, wantprefixlen = None):
#     def strCompressed(self, wantprefixlen = None):
#     def strNormal(self, wantprefixlen = None):
#     def strFullsize(self, wantprefixlen = None):
#     def strHex(self, wantprefixlen = None):
#     def strDec(self, wantprefixlen = None):
#     def iptype(self):
#     def netmask(self):
#     def strNetmask(self):
#     def len(self):
#     def __nonzero__(self):
#     def __len__(self):
#     def __add__(self, other):
#     def __sub__(self, other):
#     def __getitem__(self, key):
#     def __contains__(self, item):
#     def overlaps(self, item):
#     def __str__(self):
#     def __repr__(self):
#     def __cmp__(self, other):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __lt__(self, other):
#     def __hash__(self):
#     def net(self):
#     def broadcast(self):
#     def netmask(self):
#     def _getIPv4Map(self):
#     def reverseNames(self):
#     def reverseName(self):
#     def make_net(self, netmask):
#     def __getitem__(self, key):
#     def __repr__(self):
#     def get_mac(self):
#     def v46map(self):
#     def __init__(self, iterable=[]):
#     def __contains__(self, ip):
#     def __iter__(self):
#     def __len__(self):
#     def __add__(self, other):
#     def __sub__(self, other):
#     def __repr__(self):
#     def len(self):
#     def add(self, value):
#     def discard(self, value):
#     def optimize(self):
# def _parseAddressIPv6(ipstr):
# def parseAddress(ipstr):
# def intToIp(ip, version):
# def _ipVersionToLen(version):
# def _countFollowingZeros(l):
# def _intToBin(val):
# def _count1Bits(num):
# def _count0Bits(num):
# def _checkPrefix(ip, prefixlen, version):
# def _checkNetmask(netmask, masklen):
# def _checkNetaddrWorksWithPrefixlen(net, prefixlen, version):
# def _netmaskToPrefixlen(netmask):
# def _prefixlenToNetmask(prefixlen, version):
# def _remove_subprefix(prefix, subprefix):


import Queue
import sys
import imp
import os
from lib.core.data import th, conf, logger, paths
from lib.core.enums import TARGET_MODE_STATUS
from lib.core.settings import ESSENTIAL_MODULE_METHODS
from lib.core.exception import ToolkitValueException
from lib.controller.api import runApi
from thirdparty.IPy import IPy
    elif conf.TARGET_MODE is TARGET_MODE_STATUS.API: #conf.TARGET_MOD=5 API模式
        api_mode()

    else:
        raise ToolkitValueException('conf.TARGET_MODE value ERROR.')
    logger.info('Total: %s' % str(th.queue.qsize()))


def file_mode():
    for line in open(conf.INPUT_FILE_PATH): #读取文件中的每行并丢进队列
        sub = line.strip()
        if sub:
            th.queue.put(sub)


def cidr_mode():
    ori_str = conf.NETWORK_STR
    try:
        _list = IPy.IP(ori_str) #使用IPy插件得到IP列表
    except Exception, e:
        sys.exit(logger.error('Invalid IP/MASK,%s' % e))
    for each in _list: #将IP列表丢进队列
        th.queue.put(str(each))


def single_target_mode():
    th.queue.put(str(conf.SINGLE_TARGET_STR))


def api_mode():

# Path: lib/core/data.py

# 
# Path: lib/core/enums.py
# class TARGET_MODE_STATUS:
#     FILE = 9
#     SINGLE = 8
#     IPMASK = 7
#     RANGE = 6
#     API = 5
# 
# Path: lib/core/settings.py
# ESSENTIAL_MODULE_METHODS = ['poc']
# 
# Path: lib/core/exception.py
# class ToolkitValueException(ToolkitBaseException):
#     pass
# 
# Path: lib/controller/api.py
# def runApi():
#     output = conf.API_OUTPUT
#     dork = conf.API_DORK
#     limit = conf.API_LIMIT
#     logger.info('Activate %s API' % conf.API_MODE)
#     if conf.API_MODE is API_MODE_NAME.ZOOMEYE:
#         anslist = ZoomEyeSearch(query=dork, limit=limit, type=conf.ZOOMEYE_SEARCH_TYPE, offset=conf.API_OFFSET)
#     elif conf.API_MODE is API_MODE_NAME.BAIDU:
#         anslist = BaiduSearch(query=dork, limit=limit, offset=conf.API_OFFSET)
#     else:
#         raise ToolkitValueException('Unknown API mode')
# 
#     tmpIpFile = os.path.join(output, '%s.txt' % (time.strftime('%Y%m%d%H%M%S')))
#     with open(tmpIpFile, 'w') as fp:
#         for each in anslist:
#             if isinstance(each, list):  # for ZoomEye web type
#                 each = each[0]
#             fp.write(each + '\n')
#     return tmpIpFile
# 
# Path: thirdparty/IPy/IPy.py
# MAX_IPV4_ADDRESS = 0xffffffff
# MAX_IPV6_ADDRESS = 0xffffffffffffffffffffffffffffffff
# IPV6_TEST_MAP    = 0xffffffffffffffffffffffff00000000
# IPV6_MAP_MASK    = 0x00000000000000000000ffff00000000
#     INT_TYPES = (int,)
#     STR_TYPES = (str,)
#     INT_TYPES = (int, long)
#     STR_TYPES = (str, unicode)
# class IPint(object):
# class IP(IPint):
# class IPSet(IPSetBaseClass):
#     def __init__(self, data, ipversion=0, make_net=0):
#     def int(self):
#     def version(self):
#     def prefixlen(self):
#     def net(self):
#     def broadcast(self):
#     def _printPrefix(self, want):
#     def strBin(self, wantprefixlen = None):
#     def strCompressed(self, wantprefixlen = None):
#     def strNormal(self, wantprefixlen = None):
#     def strFullsize(self, wantprefixlen = None):
#     def strHex(self, wantprefixlen = None):
#     def strDec(self, wantprefixlen = None):
#     def iptype(self):
#     def netmask(self):
#     def strNetmask(self):
#     def len(self):
#     def __nonzero__(self):
#     def __len__(self):
#     def __add__(self, other):
#     def __sub__(self, other):
#     def __getitem__(self, key):
#     def __contains__(self, item):
#     def overlaps(self, item):
#     def __str__(self):
#     def __repr__(self):
#     def __cmp__(self, other):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __lt__(self, other):
#     def __hash__(self):
#     def net(self):
#     def broadcast(self):
#     def netmask(self):
#     def _getIPv4Map(self):
#     def reverseNames(self):
#     def reverseName(self):
#     def make_net(self, netmask):
#     def __getitem__(self, key):
#     def __repr__(self):
#     def get_mac(self):
#     def v46map(self):
#     def __init__(self, iterable=[]):
#     def __contains__(self, ip):
#     def __iter__(self):
#     def __len__(self):
#     def __add__(self, other):
#     def __sub__(self, other):
#     def __repr__(self):
#     def len(self):
#     def add(self, value):
#     def discard(self, value):
#     def optimize(self):
# def _parseAddressIPv6(ipstr):
# def parseAddress(ipstr):
# def intToIp(ip, version):
# def _ipVersionToLen(version):
# def _countFollowingZeros(l):
# def _intToBin(val):
# def _count1Bits(num):
# def _count0Bits(num):
# def _checkPrefix(ip, prefixlen, version):
# def _checkNetmask(netmask, masklen):
# def _checkNetaddrWorksWithPrefixlen(net, prefixlen, version):
# def _netmaskToPrefixlen(netmask):
# def _prefixlenToNetmask(prefixlen, version):
# def _remove_subprefix(prefix, subprefix):


# Path: lib/controller/loader.py
import Queue
import sys
import imp
import os
from lib.core.data import th, conf, logger, paths
from lib.core.enums import TARGET_MODE_STATUS
from lib.core.settings import ESSENTIAL_MODULE_METHODS
from lib.core.exception import ToolkitValueException
from lib.controller.api import runApi
from thirdparty.IPy import IPy

    elif conf.TARGET_MODE is TARGET_MODE_STATUS.API: #conf.TARGET_MOD=5 API模式
        api_mode()

    else:
        raise ToolkitValueException('conf.TARGET_MODE value ERROR.')
    logger.info('Total: %s' % str(th.queue.qsize()))


def file_mode():
    for line in open(conf.INPUT_FILE_PATH): #读取文件中的每行并丢进队列
        sub = line.strip()
        if sub:
            th.queue.put(sub)


def cidr_mode():
    ori_str = conf.NETWORK_STR
    try:
        _list = IPy.IP(ori_str) #使用IPy插件得到IP列表
    except Exception, e:
        sys.exit(logger.error('Invalid IP/MASK,%s' % e))
    for each in _list: #将IP列表丢进队列
        th.queue.put(str(each))


def single_target_mode():
    th.queue.put(str(conf.SINGLE_TARGET_STR))


def api_mode():

    conf.API_OUTPUT = os.path.join(paths.DATA_PATH, conf.API_MODE)