本文整理汇总了Python中shodan.WebAPI类的典型用法代码示例。如果您正苦于以下问题:Python WebAPI类的具体用法?Python WebAPI怎么用?Python WebAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebAPI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: autoroot
def autoroot(api_key, thread_count=10):
api = WebAPI(api_key)
search_queries = ['Server: Linux, HTTP/1.1, DIR','Mathopd/1.5p6' ]#, 'Server: Linux, HTTP/1.1, DIR-300']
for query in search_queries:
count = 0
page = 1
total = 0
while True:
results = api.search(query)
if total == 0:
total = int(results['total'])
print('Results found: %s' % results['total'])
print('Countries found: ')
pprint(results['countries'])
raw_input('press enter to start hacking')
dm = DlinkManager(results['matches'],thread_count=10)
dm.run()
page += 1
count += len(results['matches'])
if count == total:
break
print("Rooted routers count: %i" % len(rooted))
print(rooted)
示例2: locateip
def locateip(self, data):
if '!locateip' in data['recv']:
args = argv('!locateip',data['recv'])
api = WebAPI("KpYC07EoGBtGarTFXCpjsspMVQ0a5Aus")#don look
query = args['argv'][1]
try:
socket.inet_aton(query)
except socket.error:
return None
results = api.host(query)
output = []
output.append('OS: ' + str(results['os']))
output.append('City: ' + str(results['city']) + '\tPostal code: ' + str(results['postal_code']))
output.append('Area code: ' + str(results['area_code']) + '\t\tCountry code: ' + str(results['country_code']))
output.append('Region name: ' + str(results['region_name']) + '\tCountry name: ' + str(results['country_name']))
output.append('Latitude: ' + str(results['latitude']) + '\tLongitude: ' + str(results['longitude']))
ports = []
for data in results['data']:
port = data['port']
if not str(port) in ports:
ports.append(str(port))
output.append('Open ports: ' + ', '.join(ports))
ircoutput = ''
for line in output:
ircoutput += say(args['channel'],line)
return ircoutput
示例3: __init__
class Shodan:
""" Clase para buscar en Shodan """
def __init__(self,API_KEY):
self.api = WebAPI(API_KEY)
def buscar(self,cadena):
""" Busca segun la cadena dada """
try:
# Buscamos lo de la cadena pasada como parametro
resultado = self.api.search(str(cadena))
return resultado
except Exception as e:
print 'Ups! Ha ocurrido un error: %s' % e
resultado = []
return resultado
def obtener_info_host(self,IP):
""" Obtiene la info que pueda tener shodan sobre una IP """
try:
host = self.api.host(IP)
return host
except Exception as e:
print 'Ups! Ha ocurrido un error: %s' % e
host = []
return host
示例4: shodan_search
def shodan_search(search, apikey, pages):
from shodan import WebAPI
if apikey:
API_KEY = apikey
else:
API_KEY = 'ENTER YOUR API KEY HERE AND KEEP THE QUOTES'
api = WebAPI(API_KEY)
ips_found = []
try:
results = api.search(search, page=1)
total_results = results['total']
print '[+] Results: %d' % total_results
print '[*] Page 1...'
pages = max_pages(pages, total_results)
for r in results['matches']:
ips_found.append(r['ip'])
if pages > 1:
i = 2
while i <= pages:
results = api.search(search, page=i)
print '[*] Page %d...' % i
for r in results['matches']:
ips_found.append(r['ip'])
i += 1
return ips_found
except Exception as e:
print '[!] Shodan search error:', e
示例5: run
def run(self, info):
# This is where we'll collect the data we'll return.
results = []
# Skip unsupported IP addresses.
if info.version != 4:
return
ip = info.address
parsed = netaddr.IPAddress(ip)
if parsed.is_loopback() or \
parsed.is_private() or \
parsed.is_link_local():
return
# Query Shodan for this host.
try:
key = self.get_api_key()
api = WebAPI(key)
shodan = api.host(ip)
except Exception, e:
tb = traceback.format_exc()
Logger.log_error("Error querying Shodan for host %s: %s" % (ip, str(e)))
Logger.log_error_more_verbose(tb)
return
示例6: shodanquery
def shodanquery(query, api_key=None):
if not api_key or api_key == "":
return False
api = WebAPI(api_key)
if is_valid_ipv4(query):
try:
response = api.host(query)
except:
return False
else:
try:
response = api.search(query)
except:
return False
return response
示例7: __init__
class fingershodan:
def __init__(self,search,typeSearch):
self.search = search
self.typeSearch = typeSearch
self.searchList = {}
self.allCount = 0
self.__initKey()
self.__switchSearch()
def __initKey(self):
self.api = WebAPI("CvXzhcMm3YemfeNnNKE7ed9xRSCKfAhY")
def __switchSearch(self):
if self.typeSearch=="search":
self.__execSearch()
elif self.typeSearch=="lookup":
self.search = socket.gethostbyname(self.search)
self.webHost = self.api.host(self.search)
self.__execLookup()
#elif self.typeSearch=="mac":
# self.__macLocation()
def __execSearch(self):
searched = self.api.search(self.search)
for search in searched["matches"]:
try:
self.searchList["Result "+str(self.allCount)] = {"Ip":search["ip"],"Updated":search["updated"],
"Country":search["country_name"],"Latitude":search["latitude"],"Longitude":search["longitude"],
"Port":search["port"],"Data":search["data"],"Os":search["os"]}
self.allCount += 1
except:
continue
def __execLookup(self):
try:
self.searchList["Result "+str(self.allCount)] = {"Ip":self.webHost["ip"],"Country":self.webHost["country_name"],"City":self.webHost["city"],
"Os":self.webHost["os"],"Banner":self.webHost["data"][0]["banner"],"Port":self.webHost["data"][0]["port"],
"TimeStamp":self.webHost["data"][0]["timestamp"]}
except:
print "Fail Lookup"
#def __macLocation(self):
def _returnData(self):
return self.searchList
示例8: __init__
def __init__(self,host):
self.host=host
self.key = ""
if self.api =="":
print "You need an API key in order to use SHODAN database. You can get one here: http://www.shodanhq.com/"
sys.exit()
self.api = WebAPI(self.key)
示例9: shodan_search
def shodan_search(search, apikey):
if apikey:
API_KEY = args.apikey
else:
API_KEY = 'ENTER YOUR API KEY HERE AND KEEP THE QUOTES'
api = WebAPI(API_KEY)
ips_found = []
try:
results = api.search('%s' % search)
print '[+] Results: %s' % results['total']
for r in results['matches']:
ips_found.append(r['ip'])
return ips_found
except Exception as e:
print '[!] Error:', e
示例10: __init__
def __init__(self,host):
self.host=host
self.shodan_api_key = "oykKBEq2KRySU33OxizNkOir5PgHpMLv"
if self.shodan_api_key =="":
print "You need an API key in order to use SHODAN database. You can get one here: http://www.shodanhq.com/"
sys.exit()
self.api = WebAPI(self.shodan_api_key)
示例11: shodan_search
def shodan_search(search, apikey, pages):
from shodan import WebAPI
if apikey:
API_KEY = apikey
else:
API_KEY = "ENTER YOUR API KEY HERE AND KEEP THE QUOTES"
api = WebAPI(API_KEY)
ips_found = []
try:
results = api.search(search, page=1)
total_results = results["total"]
print "[+] Results: %d" % total_results
print "[*] Page 1..."
pages = max_pages(pages, total_results)
for r in results["matches"]:
# Replace the following ports with port 80 since they'll virtually never have a web server running
# ftp, ssh, telnet, smtp, smtp, netbios x3, smb
if r["port"] in [21, 22, 23, 25, 26, 137, 138, 139, 445]:
r["port"] = 80
ips_found.append("%s:%s" % (r["ip"], r["port"]))
if pages > 1:
i = 2
while i <= pages:
results = api.search(search, page=i)
print "[*] Page %d..." % i
for r in results["matches"]:
ips_found.append(r["ip"])
i += 1
return ips_found
except Exception as e:
print "[!] Shodan search error:", e
示例12: shodan_frame
def shodan_frame(port):
# Currently Supports query based on port Filter only and Displays Corresponding IP
print colored("\n[!] Shodan Search Module For NoSQL Framework Launched.....",'yellow')
api = WebAPI("API KEY GOES HERE")
if port == 5984:
query='{"couchdb":"Welcome","version":""}'
else:
query='port:%s'%(port)
result = api.search(query)
print colored("[-] Would Like to write the Results to a File",'green')
choice=raw_input()
if choice.lower()=='y':
file=open('shodan-%s.txt'%(port),'w')
for host in result['matches']:
file.write(host['ip']+"\n")
print colored('[-] File to %s/shodan-%s.txt'%(os.getcwd(),port),'green')
file.close()
else:
print colored("[-] Printing Found IP \n",'blue')
for host in result['matches']:
print colored("[-] "+host['ip'],'green')
示例13: main
def main(queue):
# Connect to Shodan
api = WebAPI(API_KEY)
# get the first page of results
res = api.search(filter)
#keep track of how many results we have left
#total_results = res['total']
total_results = res.get('total', 0)
# Start looping through results now
page = 1
try:
while(page * 100 <= total_results):
#check the matches to see if they fit what we are looking for
for host in res['matches']:
queue.put_nowait(host['ip'])
page +=1
res = api.search(filter,page)
except Exception, e:
print e
示例14: CamScanner
class CamScanner(object):
filter = "netcam"
def __init__(self, shodan_api_key):
self.api_key = shodan_api_key
self.api = WebAPI(self.api_key)
def cam_available(self, url):
try:
resp = urlopen(url, None, 10)
except (URLError, timeout):
print "Failed to contact cam: %s" % url
return False
else:
if resp.code == 200:
return True
print "Bad resp code: %d" % resp.code
return False
def get_cams(self):
results = self.api.search(self.filter)
total_pages = (results["total"] / 50) + 1
current_page = 1
skip = False
while current_page <= total_pages:
if not skip:
for result in results["matches"]:
url = "http://%s/anony/mjpg.cgi" % result["ip"]
if self.cam_available(url):
yield url, result.get("latitude"), result.get("latitude")
current_page += 1
try:
results = self.api.search(self.filter, page=current_page)
except URLError:
print "Failed to GET page %d" % current_page
skip = True
示例15: search_shodan
class search_shodan():
def __init__(self,host):
self.host=host
self.key = ""
if self.api =="":
print "You need an API key in order to use SHODAN database. You can get one here: http://www.shodanhq.com/"
sys.exit()
self.api = WebAPI(self.key)
def run(self):
try:
host = self.api.host(self.host)
return host['data']
except:
#print "SHODAN empty reply or error in the call"
return "error"