forked from p15670423/monkey
Agent: Add get_local_network_interfaces()
This commit is contained in:
parent
332649d5d1
commit
da3c6a4245
|
@ -1,7 +1,9 @@
|
|||
import itertools
|
||||
import socket
|
||||
import struct
|
||||
from ipaddress import IPv4Network
|
||||
from random import randint # noqa: DUO102
|
||||
from typing import List
|
||||
|
||||
import netifaces
|
||||
import psutil
|
||||
|
@ -9,6 +11,8 @@ import psutil
|
|||
from common.network.network_range import CidrRange
|
||||
from infection_monkey.utils.environment import is_windows_os
|
||||
|
||||
from . import NetworkInterface
|
||||
|
||||
# Timeout for monkey connections
|
||||
TIMEOUT = 15
|
||||
LOOPBACK_NAME = b"lo"
|
||||
|
@ -18,6 +22,14 @@ RTF_UP = 0x0001 # Route usable
|
|||
RTF_REJECT = 0x0200
|
||||
|
||||
|
||||
def get_local_network_interfaces() -> List[NetworkInterface]:
|
||||
for i in get_host_subnets():
|
||||
netmask_bits = IPv4Network(f"{i['addr']}/{i['netmask']}", strict=False).prefixlen
|
||||
cidr_netmask = f"/{netmask_bits}"
|
||||
|
||||
return [NetworkInterface(i["addr"], cidr_netmask) for i in get_host_subnets()]
|
||||
|
||||
|
||||
def get_host_subnets():
|
||||
"""
|
||||
Returns a list of subnets visible to host (omitting loopback and auto conf networks)
|
||||
|
|
Loading…
Reference in New Issue