当前位置: 首页>>代码示例>>Python>>正文


Python shodan.APIError方法代码示例

本文整理汇总了Python中shodan.APIError方法的典型用法代码示例。如果您正苦于以下问题:Python shodan.APIError方法的具体用法?Python shodan.APIError怎么用?Python shodan.APIError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shodan的用法示例。


在下文中一共展示了shodan.APIError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def main():

    API_KEY = input("Enter your shodan api key: ")
    # If you don't want enter your shodan key every time you can define API_KEY as a string like API_KEY = "YOUR_SHODAN_KEY"
    api = shodan.Shodan(API_KEY)
    try:
        prod = input("Enter product name: ")
        res = api.search(prod)

        print("Results found {}".format(res['total']))
        for r in res['matches']:
            print("IP: {}".format(res['ip_str']))
            print(res['data'])
            print("")

    except shodan.APIError as e:
        print("Error: {}".format(e))

    except KeyboardInterrupt:
        print("Exiting...")
        exit(0) 
开发者ID:Naategh,项目名称:PyCk,代码行数:23,代码来源:shodan-prod.py

示例2: run_shodan_search

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def run_shodan_search(self,target):
        """Collect information Shodan has for target domain name. This uses the Shodan search
        instead of host lookup and returns the target results dictionary from Shodan.

        A Shodan API key is required.

        Parameters:
        target      The domain to search for on Shodan
        """
        if self.shodan_api is None:
            pass
        else:
            try:
                target_results = self.shodan_api.search(target)
                return target_results
            except shodan.APIError as error:
                pass 
开发者ID:chrismaddalena,项目名称:ODIN,代码行数:19,代码来源:shodantools.py

示例3: run_shodan_lookup

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def run_shodan_lookup(self,target):
        """Collect information Shodan has for target IP address. This uses the Shodan host lookup
        instead of search and returns the target results dictionary from Shodan.

        A Shodan API key is required.

        Parameters:
        target      The IP address to use for the Shodan query
        """
        if self.shodan_api is None:
            pass
        else:
            try:
                target_results = self.shodan_api.host(target)
                return target_results
            except shodan.APIError as error:
                if error == "Invalid IP":
                    click.secho("[*] A domain resolved to {}, which Shodan has flagged as an invalid \
IP address. Review it and check the hostname in the final results. If it is a valid address, the \
domain may resolve to an internal asset or have a CNAME for an internal asset.",fg="yellow")
                else:
                    pass 
开发者ID:chrismaddalena,项目名称:ODIN,代码行数:24,代码来源:shodantools.py

示例4: obtain_host_info

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def obtain_host_info(self,IP):
        try:
                host = self.shodanApi.host(IP)
                if len(host) != 0:
                            # Print host info
                            print('IP: %s' % host.get('ip_str'))
                            print('Country: %s' % host.get('country_name','Unknown'))
                            print('City: %s' % host.get('city','Unknown'))
                            print('Latitude: %s' % host.get('latitude'))
                            print('Longitude: %s' % host.get('longitude'))
                            print('Hostnames: %s' % host.get('hostnames'))

                            for i in host['data']:
                               print('Port: %s' % i['port'])
                               
                            return host
        except shodan.APIError as e:
                print(' Error: %s' % e)
                return host 
开发者ID:PacktPublishing,项目名称:Mastering-Python-for-Networking-and-Security,代码行数:21,代码来源:testShodan_openssl_python3.py

示例5: obtain_host_info

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def obtain_host_info(self,IP):
        try:
                host = self.shodanApi.host(IP)
                if len(host) != 0:
                            # Print host info
                            print 'IP: %s' % host.get('ip_str')
                            print 'Country: %s' % host.get('country_name','Unknown')
                            print 'City: %s' % host.get('city','Unknown')
                            print 'Latitude: %s' % host.get('latitude')
                            print 'Longitude: %s' % host.get('longitude')
                            print 'Hostnames: %s' % host.get('hostnames')

                            for i in host['data']:
                               print 'Port: %s' % i['port']
                               
                            return host
        except shodan.APIError, e:
                print ' Error: %s' % e
                return host 
开发者ID:PacktPublishing,项目名称:Mastering-Python-for-Networking-and-Security,代码行数:21,代码来源:testShodan_openssl_python2.py

示例6: get_servers

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def get_servers(api_key, continue_flag, outdir):
    api = shodan.Shodan(api_key)
    memcached_servers = []
    try:
        results = api.search("product:memcached")
        print("Results found: {}".format(results["total"]))
        for result in results.get("matches"):
            elem = {"ip_str": result.get("ip_str"), "port": result.get("port")}
            memcached_servers.append(elem)
            print("[ ] Found memcached server at IP: {}".format(result["ip_str"]))
    except shodan.APIError as e:
        print('[-] Shodan error: %s' % e)
    if continue_flag:
        # Get files currently in output directory and remove .csv or .json extension so we just have the IP address
        currentfiles = [os.path.splitext(f)[0] for f in listdir(outdir) if isfile(join(outdir, f))]
        memcached_servers = [x for x in memcached_servers if x not in currentfiles]     
    return memcached_servers 
开发者ID:JLospinoso,项目名称:memcachedump,代码行数:19,代码来源:mcd.py

示例7: shodan_search

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def shodan_search(self, query, ss_SHODAN_API_KEY):
        shodan_api = shodan.Shodan(ss_SHODAN_API_KEY)
        try:
            shodan_search_results = shodan_api.search(query)
            self.shodan_search_result = shodan_search_results
            return self.shodan_search_result
        except shodan.APIError as e:
            print ('[!] - Error: {0}'.format(e))
            time.sleep(2)
            web_pentest() 
开发者ID:penetrate2hack,项目名称:ITWSV,代码行数:12,代码来源:pureblood.py

示例8: shodan_host_lookup

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def shodan_host_lookup(self, shodan_host, shl_SHODAN_API_KEY):
        shodan_api = shodan.Shodan(shl_SHODAN_API_KEY)
        try:
            shodan_host_lookup_results = shodan_api.host(shodan_host)
            self.shodan_host_lookup_result = shodan_host_lookup_results
            return self.shodan_host_lookup_result
        except shodan.APIError as e:
            print ('[!] - Error: {0}'.format(e))
            time.sleep(2)
            web_pentest() 
开发者ID:penetrate2hack,项目名称:ITWSV,代码行数:12,代码来源:pureblood.py

示例9: scanMongoDBIP

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def scanMongoDBIP():
    SHODAN_API_KEY = "9kwHl4vdqoXjeKl7iXOHMvXGT3ny85Ig";
    api = shodan.Shodan(SHODAN_API_KEY);
    print 'Start Scanning.....'
    try:
        results = api.search('mongoDB')

#        print 'Results found:%s' % results['total']
        for index in range(1,10):
            print str(index)+'_Attacked IP : %s' % results['matches'][index]['ip_str']
#        select = raw_input("Get more IP (y/n)?")
        select = raw_input("Select IP to attack:")
        GlobalVar.set_victim(results['matches'][int(select)]['ip_str'])
        GlobalVar.set_optionSet(0, True)
        GlobalVar.set_myIP('127.0.0.1')
        GlobalVar.set_optionSet(4, True)
        start = raw_input("Start Default Configuration Attack(y/n)?")
        if start == 'y':
            netAttacks(GlobalVar.get_victim(), GlobalVar.get_dbPort(), GlobalVar.get_myIP(), GlobalVar.get_myPort())

#        for result in results['matches']:
#            print 'Attacked IP: %s' % result['ip_str']
            #print result['data']
            #print 'hostnames:' % result['hostnames'];
            #print ' '
    except shodan.APIError, e:
        print 'Error:%s' % e
#if __name__ == "__main__":
#    scanMongoDBIP()
# (1)255.255.255.255 is a broadcast address , beginning with 255 can not be used
# (2)The last ip in each segment is a broadcast address and can not be used by a particular computer . For example, 192.168.1.255 (255 can not be used )
# (3)127.0.0.1 can not be used for communication between computers , 127 beginning unavailable
# (4)0.0.0.0 indicates an invalid address , it can not be used
# (5)10.0.0.0~10.255.255.255   192.168.0.0~192.168.255.255  172.16.0.0~172.31.255.255  are all private address
# (6)169.254.0.0 ~ 169.254.255.255 is assigned by WINDOWS operating system , the emergence of this IP on behalf of your current network can not access the 
开发者ID:youngyangyang04,项目名称:NoSQLAttack,代码行数:37,代码来源:scanIP.py

示例10: ip_details

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def ip_details(ip, json_output=False):
    try:
        api = shodan.Shodan(shodan_api_key)
        host = api.host(ip)
        if json_output:
            print(host)
            return
        print(f'IP Provided:: {ip}')
        format_dict(host, attribute='data')
    except shodan.APIError as e:
        print(e) 
开发者ID:SharadKumar97,项目名称:OSINT-SPY,代码行数:13,代码来源:ip_enum.py

示例11: get_device

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def get_device(device_name, json_output=False):
    try:
        api = shodan.Shodan(shodan_api_key)
        results = api.search(device_name)
        time.sleep(5)
        if json_output:
            print(results)
            return
        print(f"Results Found: {results['total']}")
        for result in results['matches']:
            print(f"Ip:: {result['ip_str']} | Organization:: {result['org']} |"
                  f" Domain:: {result['domains']} | ISP:: {result['isp']}")

    except shodan.APIError as e:
        print(e) 
开发者ID:SharadKumar97,项目名称:OSINT-SPY,代码行数:17,代码来源:device_search.py

示例12: fetch

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def fetch(observable, api_key):
        try:
            return shodan.Shodan(api_key).host(observable.value)
        except shodan.APIError as e:
            logging.error('Error: {}'.format(e)) 
开发者ID:yeti-platform,项目名称:yeti,代码行数:7,代码来源:shodan_api.py

示例13: search

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def search(api, search_str, limit):
    """
    Search with Shodan API
    """

    try:
        res = api.search(search_str, limit=limit)

        for banner in res["matches"]:

            # header
            print("[", end="")
            if "ip_str" in banner and banner["ip_str"]:
                print(banner["ip_str"], end=", ")
            if "hostnames" in banner and banner["hostnames"]:
                for hostname in banner["hostnames"]:
                    print(hostname, end=", ")
            if "os" in banner and banner["os"]:
                print(banner["os"], end=", ")
            if "port" in banner and banner["port"]:
                print(banner["port"], end=", ")
            if "timestamp" in banner and banner["timestamp"]:
                date = banner["timestamp"][:10]
                print(date, end="")
            print("]\n")

            # service information
            if "ssl" in banner and banner["ssl"]["cert"]["subject"]:
                b = banner["ssl"]["cert"]["subject"]
                for field in b:
                    print("{}: {}".format(field, b[field]))
                print()
            if "data" in banner and banner["data"]:
                print(banner["data"].rstrip(), end="\n\n")
        
    except shodan.APIError as err:
        print("\t// error: {}\n".format(err))
        return 0

    return res["total"] 
开发者ID:0xdea,项目名称:tactical-exploitation,代码行数:42,代码来源:seitan.py

示例14: to_file_shodan

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def to_file_shodan(queries, path_output_file, should_convert, should_add_institutions):
    """Makes a Shodan API call with each given query and writes results to output file
    :param queries: Collection of strings which present Shodan queries
    :param path_output_file: String which points to existing output file
    :param should_convert: Boolean if results should be converted
    :param should_add_institutions: boolean if an institution field should be added when converting
    """
    api = get_new_shodan_api_object()
    nr_total_results = 0
    failed_queries = set()
    for query in queries:
        print('\"' + query + '\"')
        results = 0
        with open(path_output_file, "a") as output_file:
            try:
                for banner in api.search_cursor(query):
                    banner = dict_clean_empty(banner)
                    output_file.write(json.dumps(banner) + '\n')
                    results += 1
                    print('\r' + str(results) + ' results written...', end='')
                print("")
            except shodan.APIError as e:
                print('Error: ', e)
                failed_queries.add(failed_queries)
        nr_total_results += results
    # Print failed queries if present
    if not failed_queries == set():
        print('Failed queries: ', failed_queries)

    print(str(nr_total_results) + ' total results written in ' + path_output_file)
    if should_convert:
        institutions = None
        if should_add_institutions:
            institutions = get_institutions()
        convert_file(path_output_file, 'shodan', institutions) 
开发者ID:shaanen,项目名称:osint-combiner,代码行数:37,代码来源:shodanfunctions.py

示例15: _do_search

# 需要导入模块: import shodan [as 别名]
# 或者: from shodan import APIError [as 别名]
def _do_search(self):
        while 1:
            page = self.page_queue.get()
            if page is None:
                self.page_queue.task_done()
                break

            if self._cancel_job:
                self.page_queue.task_done()
                continue

            if self._page_limit > 0 and page >= self._page_limit:
                self.page_queue.task_done()
                self.results_queue.put(None)
                continue

            try:
                results = self.api.search(self._dork, page=page)
                for item in results['matches']:
                    if not self._cancel_job:
                        self.results_queue.put(item)

                self.page_queue.task_done()
                if not self._cancel_job:
                    self.page_queue.put(self._page.inc())
            except shodan.APIError as e:
                self.page_queue.task_done()
                if "Invalid page size" in str(e):
                    self.results_queue.put(None)
                elif "Insufficient query credits" in str(e):
                    self.results_queue.put(None)
                else:
                    self.results_queue.put(e)
                continue 
开发者ID:xmendez,项目名称:wfuzz,代码行数:36,代码来源:payloadtools.py


注:本文中的shodan.APIError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。