def get_atmospherics(): # make request to office # log req response = requests.get("http://192.168.1.105:1337/module/office/read") data = response.json() if not data.get("results"): return office_reading = data["results"][0]["reading"] co2_log = Log() co2_log.type = "office-co2" co2_log.value = office_reading["co2"] sesh = get_db().session sesh.add(co2_log) temp_log = Log() temp_log.type = "office-temperature" temp_log.value = office_reading["currentTemp"] sesh.add(temp_log) sesh.commit()
def get_active_hosts(): """ Run NMAP to gather the active hosts on our network :return: """ print("Running NMAP") nmap_output = check_output(["sudo", "nmap", "-sP", "--system-dns", "192.168.1.0/24"]) print(nmap_output) nmap_output = nmap_output.decode() nmap_output = nmap_output.split("\n") output = parse_nmap_output(nmap_output) sesh = get_db().session for key in output.keys(): val = output.get(key) log = Log() log.type = "host-ip-address" log.value = key sesh.add(log) mac = val.get("mac") vendor = val.get("vendor") if mac: log = Log() log.type = "host-mac-address" log.value = mac sesh.add(log) if vendor: log = Log() log.type = "host-vendor" log.value = vendor sesh.add(log) sesh.commit()
def to_model(self): log = Log() log.type = "dns-query" log.value = self.lookup log.ts = datetime.utcfromtimestamp(int(self.timestamp)) return log