![](/img/trans.png)
[英]How to get the max memory usage of a program using psutil in Python
[英]How can I get live established UDP connections with python using psutil
我正在尝试获取连接到我的机器的目标 IP(远程主机)地址,这些地址使用 UDP 协议,但我使用 psutil 得到 Null 结果
我写的脚本
import psutil
def GetServerIP():
PROCNAME = "theprocessname.exe"
for proc in psutil.process_iter():
if proc.name() == PROCNAME:
pinfo = proc.as_dict(attrs=['pid', 'name', 'create_time'])
pidnumber = pinfo["pid"]
print("Process is runnging on number: %r" % (pidnumber))
for connection in psutil.net_connections(kind='udp4'):
if pidnumber in connection:
print(connection.raddr)
GetServerIP()
该脚本适用于 TCP 连接,但在我的本地计算机上建立的 UDP 连接上没有给出任何信息。
我通读了 psutil 文档,但仍然无法弄清楚为什么它在 UDP 上没有返回结果
我可以验证是否已建立 UDP 数据包正在使用wireshark发送和接收
如果 psutil 不适用于 UDP 是否有替代解决方案
It seems like psutil was not the right solution and path to take, turned out UDP connections are not established like TCP, so instead I switched to python scapy to capture UDP packets and it helped me resolve the destination IP address
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.