proc.py 文件源码

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

项目:opensnitch 作者: evilsocket 项目源码 文件源码
def get_pid_by_connection(src_addr, src_p, dst_addr, dst_p, proto='tcp'):
    # We always take the first element as we assume it contains only one
    # It should not be possible to keep two connections which are the same.
    for conn in psutil.net_connections(kind=proto):
        if proto == 'tcp':
            if conn.laddr != (src_addr, int(src_p)):
                continue

            if conn.raddr != (dst_addr, int(dst_p)):
                continue

        # UDP gives us a very limited dataset to work with
        elif proto == 'udp':
            if conn.laddr[1] != int(src_p):
                continue

        return conn.pid

    logging.warning("Could not find process for %s connection %s:%s -> %s:%s",
                    proto,
                    src_addr,
                    src_p,
                    dst_addr,
                    dst_p)

    return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号