# Path: lib/core/data.py

# 
# Path: lib/core/exception.py
# class ToolkitValueException(ToolkitBaseException):
#     pass
# 
# Path: lib/core/enums.py
# class API_MODE_NAME:
#     ZOOMEYE = 'ZoomEye'
#     BAIDU = 'Baidu'
# 
# Path: lib/api/zoomeye/pack.py
# def ZoomEyeSearch(query, limit, type='host', offset=0):
#     z = _initial()
#     ans = []
#     limit += offset
#     for page_n in range(int(offset / 10), int((limit + 10 - 1) / 10)):
#         data = z.dork_search(query, resource=type, page=page_n)
#         if data:
#             for i in data:
#                 ip_str = i.get('ip')
#                 if 'portinfo' in i:
#                     ip_str = ip_str + ':' + str(i.get('portinfo').get('port'))
#                 ans.append(ip_str)
#         else:
#             break
#     return ans
# 
# Path: lib/api/baidu/pack.py
# def BaiduSearch(query, limit=10, offset=0):
#     urllist = {''}
#     regex = str(ConfigFileParser().UrlFilter())
#     try:
#         while len(urllist)<limit:
#             url = "http://www.baidu.com/s?{}".format(urllib.urlencode({'wd':query,'pn':str(offset)+'0','tn':'baidurt','ie':'utf-8','bsst':'1'}))
#             request = urllib2.Request(url)
#             response = urllib2.urlopen(request)
#             html = response.read()
#             soup = BS(html, "lxml")
#             td = soup.find_all(class_='f')
#             for t in td:
#                 if regex:
#                     after_url = re.findall(regex, t.h3.a['href'])
#                     if after_url:
#                         urllist.add(after_url[0])
#                 else:
#                     after_url = iterate_path(t.h3.a['href'])
#                     for each_url in after_url:
#                         urllist.add(each_url)
#             offset = offset + 1
#         return urllist
#     except urllib2.URLError, e:
#         logger.warning('It seems like URL is wrong')
#         sys.exit(logger.error(getSafeExString(e)))


import os
import time
from lib.core.data import conf, logger
from lib.core.exception import ToolkitValueException
from lib.core.enums import API_MODE_NAME
from lib.api.zoomeye.pack import ZoomEyeSearch
from lib.api.baidu.pack import BaiduSearch
#!/usr/bin/env python
#-*- coding:utf-8 -*-



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)

# Path: lib/core/data.py

# 
# Path: lib/core/exception.py
# class ToolkitValueException(ToolkitBaseException):
#     pass
# 
# Path: lib/core/enums.py
# class API_MODE_NAME:
#     ZOOMEYE = 'ZoomEye'
#     BAIDU = 'Baidu'
# 
# Path: lib/api/zoomeye/pack.py
# def ZoomEyeSearch(query, limit, type='host', offset=0):
#     z = _initial()
#     ans = []
#     limit += offset
#     for page_n in range(int(offset / 10), int((limit + 10 - 1) / 10)):
#         data = z.dork_search(query, resource=type, page=page_n)
#         if data:
#             for i in data:
#                 ip_str = i.get('ip')
#                 if 'portinfo' in i:
#                     ip_str = ip_str + ':' + str(i.get('portinfo').get('port'))
#                 ans.append(ip_str)
#         else:
#             break
#     return ans
# 
# Path: lib/api/baidu/pack.py
# def BaiduSearch(query, limit=10, offset=0):
#     urllist = {''}
#     regex = str(ConfigFileParser().UrlFilter())
#     try:
#         while len(urllist)<limit:
#             url = "http://www.baidu.com/s?{}".format(urllib.urlencode({'wd':query,'pn':str(offset)+'0','tn':'baidurt','ie':'utf-8','bsst':'1'}))
#             request = urllib2.Request(url)
#             response = urllib2.urlopen(request)
#             html = response.read()
#             soup = BS(html, "lxml")
#             td = soup.find_all(class_='f')
#             for t in td:
#                 if regex:
#                     after_url = re.findall(regex, t.h3.a['href'])
#                     if after_url:
#                         urllist.add(after_url[0])
#                 else:
#                     after_url = iterate_path(t.h3.a['href'])
#                     for each_url in after_url:
#                         urllist.add(each_url)
#             offset = offset + 1
#         return urllist
#     except urllib2.URLError, e:
#         logger.warning('It seems like URL is wrong')
#         sys.exit(logger.error(getSafeExString(e)))


# Path: lib/controller/api.py
import os
import time
from lib.core.data import conf, logger
from lib.core.exception import ToolkitValueException
from lib.core.enums import API_MODE_NAME
from lib.api.zoomeye.pack import ZoomEyeSearch
from lib.api.baidu.pack import BaiduSearch

#!/usr/bin/env python
#-*- coding:utf-8 -*-



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: