topology.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:wifimitm 作者: mvondracek 项目源码 文件源码
def update(self, print_stream: Optional[TextIO]=None, print_prefix: Optional[str]='MITMf 1> '):
        """
        Update state of running process from process' feedback.
        Read new output from stdout and stderr, check if process is alive.
        :type print_stream: Optional[TextIO]
        :param print_stream: Print information about HTTP traffic from MITMf's stdout to provided stream.
        :type print_prefix: Optional[str]
        :param print_prefix: Prepend provided string in the beginning of every line printed to `print_stream`.
        """
        super().update()
        # Is process running? State would be changed after reading stdout and stderr.
        self.poll()

        # check every added line in stdout
        if self.stdout_r and not self.stdout_r.closed:
            for line in self.stdout_r:
                if self.state == self.State.STARTED and line == '|_ SMB server online\n':
                    self.state = self.State.SPOOFING

                elif self.state == self.State.SPOOFING and line != '\n':
                    if print_stream:
                        print(print_prefix + line, end='', file=print_stream)

        # check every added line in stderr
        if self.stderr_r and not self.stderr_r.closed:
            for line in self.stderr_r:
                if ' * Running on http://127.0.0.1:9999/ (Press CTRL+C to quit)\n' == line:
                    continue
                # NOTE: stderr should be now empty
                logger.warning("Unexpected stderr of 'mitmf': '{}'. {}".format(line, str(self)))

        # Change state if process was not running in the time of poll() call in the beginning of this method.
        # NOTE: Process' poll() needs to be called in the beginning of this method and returncode checked in the end
        # to ensure all feedback (stdout and stderr) is read and states are changed accordingly.
        # If the process exited, its state is not changed immediately. All available feedback is read and then
        # the state is changed to self.State.TERMINATED. State, flags,stats and others can be changed during reading
        # the available feedback even if the process exited. But self.State.TERMINATED is assigned here if
        # the process exited.
        if self.returncode is not None:
            self.state = self.State.TERMINATED
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号