Ejemplo n.º 1
0
 def scan(self, camera_type, url_scheme = '', check_empty_url='',check_empty = True, tag=True, search_q="webcams"):
     if url_scheme == '':
         url_scheme = self.default_url_scheme
     if self.SHODAN_API_KEY == '':
         print("[red]Please set up shodan API key in environ![/red]")
         return
     spinner = Halo(text='Looking for possible servers...', spinner='dots')
     spinner.start()
     if tag and (not self.clarifai_initialized):
         self.init_clarifai()
     try:
         results = self.api.search(search_q)
         spinner.succeed("Done")
     except:
         spinner.fail("Get data from API failed")
         return
     max_time = len(results["matches"])*10
     print(f"maximum time:{max_time} seconds")
     camera_type_list = []
     for result in results["matches"]:
         if camera_type in result["data"]:
             camera_type_list.append(result)
     cnt = 0
     for result in camera_type_list:
         url = f"http://{result['ip_str']}:{result['port']}"
         cnt+=1
         print(f"{cnt}/{len(camera_type_list)}")
         try:
             r = requests.get(url, timeout=5)
             if r.status_code == 200:
                 if check_empty == False:
                     print(
                         url_scheme.format(ip=result['ip_str'], port=result['port'])
                     )
                 else:
                     is_empty = self.check_empty(check_empty_url.format(url=url))
                     if is_empty:
                         print(
                             url_scheme.format(ip=result['ip_str'], port=result['port'])
                         )
                     else:
                         spinner.close()
                         continue
                 if tag:
                     tags = self.tag_image(check_empty_url.format(url=url))
                     for t in tags:
                         print(f"|[green]{t}[/green]|",end=" ")
                     if len(tags)==0:
                         print("[i green]no description[i green]",end="")
                     print()
                 spinner.close()
             else:
                 print("[red]webcam not avaliable[/red]")
         except KeyboardInterrupt:
             print("[red]terminating...")
             break
         except:
             continue
Ejemplo n.º 2
0
    def scan(self,
             camera_type,
             url_scheme='',
             check_empty_url='',
             check_empty=True,
             tag=True,
             search_q="webcams"):
        if url_scheme == '':
            url_scheme = self.default_url_scheme

        if tag and (not self.clarifai_initialized):
            self.init_clarifai()
        spinner = Halo(text='Looking for possible servers...', spinner='dots')
        spinner.start()
        try:
            results = self.api.search(search_q)
            spinner.succeed("Done")
        except:
            spinner.fail("Get data from API failed")
        max_time = len(results["matches"]) * 10
        print(f"maximum time:{max_time} seconds")
        for result in results["matches"]:
            if camera_type in result["data"]:
                url = f"http://{result['ip_str']}:{result['port']}"
                try:
                    r = requests.get(url, timeout=5)
                    if r.status_code == 200:
                        if check_empty == False:
                            print(
                                url_scheme.format(ip=result['ip_str'],
                                                  port=result['port']))
                        else:
                            is_empty = self.check_empty(
                                check_empty_url.format(url=url))
                            if is_empty:
                                print(
                                    url_scheme.format(ip=result['ip_str'],
                                                      port=result['port']))
                            else:
                                spinner.close()
                                continue
                        if tag:
                            tags = self.tag_image(
                                check_empty_url.format(url=url))
                            for t in tags:
                                print(f"|[green]{t}[/green]|", end=" ")
                            if len(tags) == 0:
                                print("[i green]no description[i green]",
                                      end="")
                            print()
                        spinner.close()
                except:
                    continue
Ejemplo n.º 3
0
 def scan(self,
          camera_type,
          url_scheme='',
          check_empty_url='',
          check_empty=True,
          tag=True,
          search_q="webcams",
          loc=True):
     print(f"loc:{loc}, check_empty:{check_empty}, tag:{tag}")
     if url_scheme == '':
         url_scheme = self.config['default']['url_scheme']
     if self.SHODAN_API_KEY == '':
         print("[red]Please set up shodan API key in environ![/red]")
         return
     spinner = Halo(text='Looking for possible servers...', spinner='dots')
     spinner.start()
     if tag and (not self.clarifai_initialized):
         self.init_clarifai()
     try:
         results = self.api.search(search_q)
         spinner.succeed("Done")
     except:
         spinner.fail("Get data from API failed")
         return
     max_time = len(results["matches"]) * 10
     print(f"maximum time: {max_time} seconds")
     camera_type_list = []
     for result in results["matches"]:
         if camera_type in result["data"]:
             camera_type_list.append(result)
     store = []
     cnt = 0
     for result in camera_type_list:
         url = f"http://{result['ip_str']}:{result['port']}"
         cnt += 1
         try:
             r = requests.get(url, timeout=5)
             if r.status_code == 200:
                 if check_empty == False:
                     print(
                         url_scheme.format(ip=result['ip_str'],
                                           port=result['port']))
                 else:
                     is_empty = self.check_empty(
                         check_empty_url.format(url=url))
                     if is_empty:
                         store.append(result)
                         print(
                             url_scheme.format(ip=result['ip_str'],
                                               port=result['port']))
                     else:
                         print("[red]webcam is empty[/red]")
                         spinner.close()
                         continue
                 if loc:
                     host = self.api.host(result['ip_str'])
                     country_name = host['country_name']
                     country_code = host['country_code']
                     tz = pytz.timezone(country_code)
                     dt = datetime.now(tz)
                     ns = dt.strftime('%H:%M')
                     print(f"{country_name} {ns}")
                 if tag:
                     tags = self.tag_image(check_empty_url.format(url=url))
                     for t in tags:
                         print(f"|[green]{t}[/green]|", end=" ")
                     if len(tags) == 0:
                         print("[i green]no description[i green]", end="")
                     print()
                     store[-1]["tags"] = tags
                 spinner.close()
         except KeyboardInterrupt:
             print("[red]terminating...")
             break
         except:
             continue
     return store
Ejemplo n.º 4
0
 def scan(self,
          camera_type,
          url_scheme="",
          check_empty_url="",
          check_empty=True,
          tag=True,
          geoip=True,
          search_q="webcams",
          debug=False):
     print(f"loc:{geoip}, check_empty:{check_empty}, tag:{tag}")
     if url_scheme == "":
         url_scheme = self.config["default"]["url_scheme"]
     if self.SHODAN_API_KEY == "":
         print("[red]Please set up shodan API key in environ![/red]")
         return
     spinner = Halo(text="Looking for possible servers...", spinner="dots")
     spinner.start()
     if tag and (not self.clarifai_initialized):
         self.init_clarifai()
     if geoip and (not self.geoip_initialized):
         self.init_geoip()
     try:
         results = self.api.search(search_q)
         spinner.succeed("Done")
     except:
         spinner.fail("Get data from API failed")
         if debug:
             handle()
         return
     max_time = len(results["matches"]) * 10
     print(f"maximum time: {max_time} seconds")
     camera_type_list = []
     for result in results["matches"]:
         if camera_type in result["data"]:
             camera_type_list.append(result)
     store = []
     cnt = 0
     for result in camera_type_list:
         url = f"http://{result['ip_str']}:{result['port']}"
         cnt += 1
         try:
             r = requests.get(url, timeout=5)
             if r.status_code == 200:
                 if not check_empty:
                     print(
                         url_scheme.format(ip=result["ip_str"],
                                           port=result["port"]))
                 else:
                     is_empty = self.check_empty(
                         check_empty_url.format(url=url))
                     if is_empty:
                         store.append(result)
                         print(
                             url_scheme.format(ip=result["ip_str"],
                                               port=result["port"]))
                     else:
                         print("[red]webcam is empty[/red]")
                         spinner.close()
                         continue
                 if geoip:
                     country, region, hour, minute = self.locator.locate(
                         result["ip_str"])
                     print(
                         f":earth_asia:[green]{country} , {region} {hour}:{minute}[/green]"
                     )
                     store[-1]["country"] = country
                     store[-1]["region"] = region
                 if tag:
                     tags = self.tag_image(check_empty_url.format(url=url))
                     for t in tags:
                         print(f"|[green]{t}[/green]|", end=" ")
                     if len(tags) == 0:
                         print("[i green]no description[i green]", end="")
                     print()
                     store[-1]["tags"] = tags
                 spinner.close()
         except KeyboardInterrupt:
             print("[red]terminating...")
             break
         except:
             if debug:
                 handle()
             continue
     return store