MCPcopy Create free account
hub / github.com/secdev/scapy / autorun_get_interactive_session

Function autorun_get_interactive_session

scapy/autorun.py:153–179  ·  view source on GitHub ↗

Create an interactive session and execute the commands passed as "cmds" and return all output :param cmds: a list of commands to run :param timeout: timeout in seconds :returns: (output, returned) contains both sys.stdout and sys.stderr logs

(cmds, **kargs)

Source from the content-addressed store, hash-verified

151
152
153def autorun_get_interactive_session(cmds, **kargs):
154 # type: (str, **Any) -> Tuple[str, Any]
155 """Create an interactive session and execute the
156 commands passed as "cmds" and return all output
157
158 :param cmds: a list of commands to run
159 :param timeout: timeout in seconds
160 :returns: (output, returned) contains both sys.stdout and sys.stderr logs
161 """
162 sstdout, sstderr, sexcepthook = sys.stdout, sys.stderr, sys.excepthook
163 sw = StringWriter()
164 h_old = log_scapy.handlers[0]
165 log_scapy.removeHandler(h_old)
166 log_scapy.addHandler(logging.StreamHandler(stream=sw))
167 try:
168 try:
169 sys.stdout = sys.stderr = sw
170 sys.excepthook = sys.__excepthook__
171 res = autorun_commands_timeout(cmds, **kargs)
172 except StopAutorun as e:
173 e.code_run = sw.s
174 raise
175 finally:
176 sys.stdout, sys.stderr, sys.excepthook = sstdout, sstderr, sexcepthook
177 log_scapy.removeHandler(log_scapy.handlers[0])
178 log_scapy.addHandler(h_old)
179 return sw.s, res
180
181
182def autorun_get_interactive_live_session(cmds, **kargs):

Calls 2

StringWriterClass · 0.85
autorun_commands_timeoutFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…