def get_data(val): key = get_key(val) res = requests.get( f"http://api.airvisual.com/v2/nearest_city?key={key}").json() with open("data.json", "w") as fh: fh.write(json.dumps(res)) return "success", 200
class Config: SECRET_KEY = os.environ.get('SECRET_KEY') or get_key() # lot more options ADMIN = os.environ.get('ADMIN') SQLALCHEMY_TRACK_MODIFICATIONS = False @staticmethod def init_app(app): pass
def check_events_keydown(event, settings, targets, aim, sounds): letter = get_key(event) for target in targets.copy(): if target.letter == letter: aim.move(target.rect.centerx, target.rect.centery) aim.see_me = True sounds.beep.play() targets.remove(target) break
def __memoize(*args, **kw): #5 """This replaces the original function. """ key = get_key(function, *args, **kw) #6 try: return cache[key] #7 except KeyError: value = function(*args, **kw) #8 cache[key] = value #9 return value #10
def cymon_query(query, type): """ This function queries cymon.io for threat intel information Cymon is very cool, in that it gives time information, such as which event happened in which time, prerequisite: Create an cymon account, and generate an API key, the API key has its limitation, see the reference links for more details Also paste the API key in config.txt, cymon_key section Ex: cymon_key:<your key here> Ex: >>> from cymon_intel import cymon_query For IP query >>> cymon_query("1.1.1.1","IP") For Domain Query >>> cymon_query("www.google.com","Domain") Response For cymon Example: {'count': 469, 'next': 'https://cymon.io/api/nexus/v1/ip/1.1.1.1/events?limit=10&offset=10', 'previous': None, 'results': [{'created': '2018-11-22T19:04:18Z', 'description': 'Domain: www.nlus-romania.ro', 'details_url': None, 'tag': 'phishing', 'title': 'Phishing reported by Google SafeBrowsing', 'updated': '2018-11-22T19:04:18Z'}, {'created': '2018-11-22T19:03:51Z', 'description': 'Domain: nlus-romania.ro', 'details_url': None, 'tag': 'phishing', 'title': 'Phishing reported by Google SafeBrowsing', 'updated': '2018-11-22T19:03:51Z'}, {'created': '2018-10-27T18:06:07Z', 'description': 'Domain: c.dzytccjq.com', 'details_url': None, 'tag': 'malware', The above is the detailed response from cymon, If you want more detailed output, modify the script per your re quirement Reference: https://cymon.io/cp/api https://cymon.io/api/docs/#!/ip/Malware_list """ api_key = get_key("cymon_key") if type == "ip": url = "https://cymon.io/api/nexus/v1/ip/{}/events".format(query) elif type == "domain": url = "https://cymon.io/api/nexus/v1/domain/{}".format(query) headers = {"authorization": "Token {}".format(api_key)} response = requests.get(url, headers=headers) res = json.loads(response.text) return res
def shodan_query(address, type): if type == "mal": address = "category:malware " + address key = get_key("shodan") searcher = shodan.Shodan(key) # Shodan Object # query shodan results = searcher.search(address) #return results print("Result found: {}".format(results['total'])) for result in results["matches"]: print(result)
def __memoize(*args, **kw): """This replaces the original function. """ key = get_key(function, *args, **kw) try: value_age, value = storage[key] #2 deprecated = (age != 0 and (value_age + age) < time.time()) #3 except KeyError: deprecated = True #4 if not deprecated: return value #5 storage[key] = time.time(), function(*args, **kw) #6 return storage[key][1] #7
def hybrid_query(query, type): ''' Queries hybrid analysis for informationn\n Hybrid is a great resource to see what activities the IP address was involved in Usage: from hybrid import hybrid_query hybrid_query("104.27.163.228") ''' key = get_key( "Hybrid") # Get the key from config file, Change it as necessary url = "https://www.hybrid-analysis.com/api/v2/search/terms" # The api url headers = { "api-key": key, "user-agent": "Falcon Sandbox", "accept": "application/json" } # The request headers if type == "domain": data = {"domain": query} # The data to post elif type == "ip": data = {"host": query} else: return resp = requests.post(url, headers=headers, data=data) response = json.loads(resp.text) if response["count"] == 0: # If no result was recieved print("Could not recieve value") return else: c = response["count"] print("[+] Hybrid analysis has got {} matches\n".format(c)) for i in range(0, c): # Parsing the data print("Match No: {}\n".format(i)) verdict = response["result"][i]['verdict'] av_detect = response["result"][i]['av_detect'] threat_score = response["result"][i]['threat_score'] hash = response["result"][i]['sha256'] submit_name = response["result"][i]['submit_name'] analyzed_in = response["result"][i]['analysis_start_time'] msg = "Verdit: {}\nAV_Detection: {}\nThreat_Score: {}\nSHA256_HASH: {}\nSubmit_Name: {}\nAnalyzed_in: {}\n".\ format(verdict,av_detect,threat_score,hash,submit_name,analyzed_in) print(msg)
def query_malshare(query): ''' Get Malshare data: Prerequisite: You are expected to have obtained a malshare API key, and put it in config.txt Ex: Config.txt .... malshare:<your API key here> Usage: >>> from malshare_query import query_malshare >>> query_malshare("domainname or IP address") ''' key = get_key("malshare") # The query is super late url = "https://malshare.com/api.php?api_key={}&action=search&query={}".format( key, query) # malshare API URL resp = requests.get(url).text print(json.dumps(resp, sort_keys=True, indent=4, separators=(',', ': ')))
def run(self): maze = self.maze play = True while play: # Start if self.start == True: maze = self.next_position(maze, [0, 0], 'inicio') self.print_maze(maze) self.start = False # Simulate Key if self.ia_flag: if self.ia_steps_count < len(self.ia_steps): key = gk.simulate_key(self.ia_steps[self.ia_steps_count]) # Go to next position maze = self.next_position(maze, self.actual, key) self.print_maze(maze) self.ia_steps_count += 1 else: #print(f"Terminou os steps da IA\nActual Steps: {self.actual}") play = False #self.print_maze(maze) else: if self.steps < self.numero_de_movimentos: # Get Key key = gk.get_key() #key = gk.simulate_key(self.label[self.label_counter]) self.label_counter += 1 # Go to next position maze = self.next_position(maze, self.actual, key) if self.actual == [ len(self.maze[0]) - 1, len(self.maze[1]) - 1 ]: #print("ACABO ACABO ACABO!") pass else: self.print_maze(maze) #print("--------------------------------------------") else: print( f"Você ultrapassou o número de movimentos permitidos: {self.numero_de_movimentos}" ) play = False if key == 'q': play = False if self.finish: play = False
from snake import Snake from apple import Apple #map - nowy obiekt my_map = Map(10, 10, ' ') #snake - nowy obiekt my_snake = Snake(my_map.size_x, my_map.size_y, 5, 5) #apple - nwy obiekt my_apple = Apple(my_map.size_x, my_map.size_y) #socre - int zaczyna się od 0 score = 0 my_get_key = get_key() while True: # wyczyść ekran clear_console() # wyczyść mapę my_map.clean() #pobierz wciśnięty klawisz my_key = my_get_key() # zmien kierunek węża na podstawie wcisnnietego klawisza # jak ESC to wyjdź z gry if my_key == 299: # w lewo my_snake.direction.x = -1 my_snake.direction.y = 0