def run(args, output=sys.stdout, stdin=sys.stdin,
stdin_buffer=sys.stdin.buffer):
"""Observe an Ethernet interface and print beaconing packets."""
# First, become a progress group leader, so that signals can be directed
# to this process and its children; see p.u.twisted.terminateProcess.
os.setpgrp()
network_monitor = None
if args.input_file is None:
if args.interface is None:
raise ActionScriptError("Required argument: interface")
cmd = sudo(
[get_path("/usr/lib/maas/beacon-monitor"), args.interface])
network_monitor = subprocess.Popen(
cmd, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE)
infile = network_monitor.stdout
else:
if args.input_file == '-':
mode = os.fstat(stdin.fileno()).st_mode
if not stat.S_ISFIFO(mode):
raise ActionScriptError("Expected stdin to be a pipe.")
infile = stdin_buffer
else:
infile = open(args.input_file, "rb")
return_code = observe_beaconing_packets(input=infile, out=output)
if return_code is not None:
raise SystemExit(return_code)
if network_monitor is not None:
return_code = network_monitor.poll()
if return_code is not None:
raise SystemExit(return_code)
评论列表
文章目录