def lsof_processor(self): #dbr.ok(lsof_netcon, {"command" : "text", "pid" : "text", "user" : "text", "datagram" : "text", "name" : "text"}) file = open("bash/output/lsof-network.output") lines = [line.split(" ") for line in file.readlines()] file.close() for int in range(0, len(lines)): lines[int] = [item for item in lines[int] if item != ""] lines[int] = [lines[int][0], lines[int][1], lines[int][2], lines[int][7], lines[int][8]] organized_data = {} organized_data["command"] = lines[int][0] organized_data["pid"] = lines[int][1] organized_data["user"] = lines[int][2] organized_data["datagram"] = lines[int][3] organized_data["name"] = lines[int][4] #print "Logged {}".format(organized_data["name"]) dbr().ok("lsof_netcon") dbr().fill("lsof_netcon", organized_data) log("dbd", "res", "lsof network connection processor")
import subprocess from config import config import time from dbr import * from logger import logger log = logger().log dbr = dbr() class list_connections(): def lsof(): subprocess.call(config().bash().netcon()) # calls config for location of bash script that reveals network connections log("exc", ".sh", config().bash().netcon(), "list connections") class connection_output_processor(): def lsof_processor(self): #dbr.ok(lsof_netcon, {"command" : "text", "pid" : "text", "user" : "text", "datagram" : "text", "name" : "text"}) file = open("bash/output/lsof-network.output") lines = [line.split(" ") for line in file.readlines()] file.close() for int in range(0, len(lines)): lines[int] = [item for item in lines[int] if item != ""] lines[int] = [lines[int][0], lines[int][1], lines[int][2], lines[int][7], lines[int][8]] organized_data = {} organized_data["command"] = lines[int][0] organized_data["pid"] = lines[int][1] organized_data["user"] = lines[int][2] organized_data["datagram"] = lines[int][3] organized_data["name"] = lines[int][4] #print "Logged {}".format(organized_data["name"]) dbr().ok("lsof_netcon")