python - 如何使用 scapy 获取我自己的本地 IP?

标签 python ip scapy

我找不到仅使用 scapy 来查找本地 IP 地址的方法(而不是 Python 的标准库)。
我发现的唯一解决方法是发送一个虚拟包并使用它从源字段中检索地址,但我觉得这不是一个好的解决方案。

最佳答案

如果你看看 https://scapy.readthedocs.io/en/latest/routing.html#get-local-ip-ip-of-an-interface
您可以使用获取任何接口(interface)的本地 IP

>>> ip = get_if_addr(conf.iface)  # default interface
>>> ip = get_if_addr("eth0")
>>> ip
'10.0.0.5'

关于python - 如何使用 scapy 获取我自己的本地 IP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49029725/

相关文章:

python - 身份验证失败 : [Errno 1] _ssl. c:510: 错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败

python - 使用Dataset API和Keras编写summary.scalar

python - 如何将任何 ip 地址转换为斜杠 24 前缀

Tomcat : How to redirect external ip address access to an other location

python - 这行 Python 代码的作用是什么?

python - CNN keras中图像的混淆矩阵

c# - c# 中的服务器变量缺少 HTTP_X_FORWARDED_FOR

python - 使用 scapy 作为 MITM 即时更改数据包

python - scapy 中未定义名称 'raw'

python - 如何使用 scapy 和 python 提取 SSL/TLS 消息?