def __init__(self, interface: WirelessInterface, capture_file: Optional[BinaryIO] = None):
"""
:type capture_file: Optional[BinaryIO]
:param capture_file: file for writing packet capture
:type interface: WirelessInterface
:param interface: wireless interface for capture
"""
self.state = self.State.STARTED
self.flags = self.__initial_flags()
self.stats = self.__initial_stats()
self.interface = interface # type: WirelessInterface
self.capture_file = capture_file
# If `capture_file` was None, dumpcap will create capture file in /tmp. `self.tmp_capture_file_path` is set
# during `self.update`.
self.tmp_capture_file_path = None
cmd = ['dumpcap',
'-i', self.interface.name]
stdout = None
if self.capture_file:
# If `capture_file` was provided, set dumpcap to write raw packet data to stdout...
cmd.append('-w')
cmd.append('-')
# ... and redirect dumpcap's stdout to provided `capture_file`.
stdout = self.capture_file
super().__init__(cmd, stdout=stdout)
评论列表
文章目录