Python view all networked application information of this machine

from os.path import basename
from psutil import net_connections, Process

print("  程序文件名:\t\t本地地址:\t\t\t\t\t远程地址:\t\t\t\t连接状态:")
for conn in net_connections('all'):
    laddr, raddr, status, pid = conn[3:]
    if not raddr:
        continue
    else:
        try:
            filename = basename(Process(pid).exe())
        except:
            pass
    print(filename,laddr,raddr,status,sep="\t")

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_43873198/article/details/107447607