class Replaycenter: def __init__(self, interface=None): # singleton logger self.logger = CustomLogger().get_logger() # error codes self.codes = DotMap() self.codes.ok = 0 self.codes.error = -1 self.codes.missing_iface = -2 self.codes.missing_pcap = -3 if interface is not None: self.interface = interface else: pass def replay(self, bundle, interface="eth1", inter_pkt_delay=0): replay_status = None # Check if interface is provided if self.interface is None: self.logger.error("Replay interface must be provided.") return self.codes.missing_iface else: pass # Check if pcaps are provided if "pcaps" not in bundle: self.logger.warning("Pcaps not found, skipping.") return self.codes.missing_pcap else: pass # Replay pcap after done with checks pcaps = bundle["pcaps"] for pcap in pcaps: self.logger.info("Replay Pcap: {}".format(pcap)) if os.path.isfile(pcap): try: pkts = rdpcap(pcap) for pkt in pkts: sendp(pkt, verbose=False, iface=interface, inter=inter_pkt_delay) except Exception as e: self.logger.error(e) replay_status = self.codes.error # Done replaying pcaps without error replay_status = self.codes.ok return replay_status
# Take parameters # ip = args["ipaddress"] # username = os.environ.get("SHIELDX_USER") # password = os.environ.get("SHIELDX_PASS") ip = "172.16.100.52" username = "******" password = "******" action = args["action"] # Initialize logger logger = CustomLogger().get_logger() if username is None or password is None: logger.warning("Please set username and password as environment variables.") sys.exit() # Establish REST connection sx_session = SxSession(ip=ip, username=username, password=password) sx_session.login() try: virtual_patch_rg = VirtualPatchRG(sx_session, logger, ip_list) except KeyboardInterrupt as e: logger.info("Task done. Goodbye.") except Exception as e: logger.error(e) # Logout
default="check", help="Action: patch | check | cleanup", required=False) args = vars(parser.parse_args()) # Take parameters ip = args["ipaddress"] username = os.environ.get("SHIELDX_USER") password = os.environ.get("SHIELDX_PASS") action = args["action"] # Initialize logger logger = CustomLogger().get_logger() if username is None or password is None: logger.warning( "Please set username and password as environment variables.") sys.exit() # Establish REST connection sx_session = SxSession(ip=ip, username=username, password=password) sx_session.login() try: # Initialize virtual_patch = VirtualPatch(sx_session, logger) # Artifacts artifact = { "rg_name": "virtual_patch_rg", "tpp_name": "virtual_patch_tpp", "sps_name": "virtual_patch_sps",