Closed 06kellyjac closed 2 years ago
Hi @06kellyjac
Another nice network library to try out is pyroute2: https://github.com/svinota/pyroute2
from pyroute2 import IPDB
ip = IPDB()
# interface index:
print(ip.routes['default']['oif'])
# interface details:
print(ip.interfaces[ip.routes['default']['oif']])
# release DB
ip.release()
I don't think Windows is supported but there is a powershell snippet that can be used. The script below provides source IP address for default network interface (I.E. interface which routes traffic to 0.0.0.0/0):
from subprocess import check_output
src_ip = check_output((
"powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy bypass -Command ""& {"
"Get-NetRoute –DestinationPrefix '0.0.0.0/0' | Select-Object -First 1 | "
"Get-NetIPAddress | Select-Object -ExpandProperty IPAddress"
"}"""
)).decode().strip()
print(src_ip)
The same for the default network interface itself:
check_output((
"powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy bypass -Command ""& {"
"Get-NetRoute –DestinationPrefix '0.0.0.0/0' | Select-Object -First 1 | "
"Get-NetIPConfiguration"
"}"""
)).decode().strip()
What happened
Since 2021-05-31 netifaces has been marked as needing a maintainer and at some point since then the repo has been marked as archived
kube-hunter might need to move to a different library or maintain netifaces
ifaddr has what seems to be a small subset of the functionality but can't grab the "default" interface
https://github.com/pydron/ifaddr/issues/41