MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / run_nmap_command

Method run_nmap_command

nmap_logger.py:82–122  ·  view source on GitHub ↗

Run an nmap command and log both the command and its results Args: command: List of command arguments (should start with 'nmap') context: Additional context for logging **kwargs: Additional arguments to pass to subprocess.run

(self, command: List[str], context: str = "", **kwargs)

Source from the content-addressed store, hash-verified

80 self.logger.info(f"OPERATION: {operation}{details_str}")
81
82 def run_nmap_command(self, command: List[str], context: str = "", **kwargs) -> subprocess.CompletedProcess:
83 """
84 Run an nmap command and log both the command and its results
85
86 Args:
87 command: List of command arguments (should start with 'nmap')
88 context: Additional context for logging
89 **kwargs: Additional arguments to pass to subprocess.run
90
91 Returns:
92 subprocess.CompletedProcess object
93 """
94 # Ensure we're dealing with an nmap command
95 if not command or command[0] != 'nmap':
96 raise ValueError("Command must start with 'nmap'")
97
98 # Log the command
99 self.log_command(command, context)
100
101 # Set default kwargs for subprocess.run
102 run_kwargs = {
103 'capture_output': True,
104 'text': True,
105 **kwargs
106 }
107
108 try:
109 # Execute the command
110 result = subprocess.run(command, **run_kwargs)
111
112 # Log the result
113 self.log_result(result.stdout, result.stderr, result.returncode, context)
114
115 return result
116
117 except Exception as e:
118 # Log the exception
119 with self.lock:
120 context_str = f" ({context})" if context else ""
121 self.logger.error(f"EXCEPTION{context_str}: {str(e)}")
122 raise
123
124# Global instance for use throughout Ragnar
125nmap_logger = NmapLogger()

Callers 1

scan_vulnerabilitiesMethod · 0.80

Calls 4

log_commandMethod · 0.95
log_resultMethod · 0.95
errorMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected