forked from p15670423/monkey
get subnets is now cross OS since it's identical + remove broadcast key since we don't have anything to do with it.
This commit is contained in:
parent
7b4fb5d4f0
commit
1bd633a0b1
|
@ -9,6 +9,24 @@ import netifaces
|
|||
from subprocess import check_output
|
||||
from random import randint
|
||||
|
||||
|
||||
def get_host_subnets():
|
||||
ipv4_nets = [netifaces.ifaddresses(interface)[netifaces.AF_INET]
|
||||
for interface in netifaces.interfaces()
|
||||
if netifaces.AF_INET in netifaces.ifaddresses(interface)
|
||||
]
|
||||
# flatten
|
||||
ipv4_nets = itertools.chain.from_iterable(ipv4_nets)
|
||||
# remove loopback
|
||||
ipv4_nets = [network for network in ipv4_nets if network['addr'] != '127.0.0.1']
|
||||
# remove auto conf
|
||||
ipv4_nets = [network for network in ipv4_nets if not network['addr'].startswith('169.254')]
|
||||
for network in ipv4_nets:
|
||||
if 'broadcast' in network:
|
||||
network.pop('broadcast')
|
||||
return ipv4_nets
|
||||
|
||||
|
||||
if sys.platform == "win32":
|
||||
|
||||
def local_ips():
|
||||
|
@ -16,20 +34,6 @@ if sys.platform == "win32":
|
|||
return socket.gethostbyname_ex(local_hostname)[2]
|
||||
|
||||
|
||||
def get_host_subnets():
|
||||
ipv4_nets = [netifaces.ifaddresses(interface)[netifaces.AF_INET]
|
||||
for interface in netifaces.interfaces()
|
||||
if netifaces.AF_INET in netifaces.ifaddresses(interface)
|
||||
]
|
||||
# flatten
|
||||
ipv4_nets = itertools.chain.from_iterable(ipv4_nets)
|
||||
# remove loopback
|
||||
ipv4_nets = [network for network in ipv4_nets if network['addr'] != '127.0.0.1']
|
||||
# remove auto conf
|
||||
ipv4_nets = [network for network in ipv4_nets if not network['addr'].startswith('169.254')]
|
||||
return ipv4_nets
|
||||
|
||||
|
||||
def get_routes():
|
||||
raise NotImplementedError()
|
||||
|
||||
|
@ -37,20 +41,6 @@ else:
|
|||
from fcntl import ioctl
|
||||
|
||||
|
||||
def get_host_subnets():
|
||||
ipv4_nets = [netifaces.ifaddresses(interface)[netifaces.AF_INET]
|
||||
for interface in netifaces.interfaces()
|
||||
if netifaces.AF_INET in netifaces.ifaddresses(interface)
|
||||
]
|
||||
# flatten
|
||||
ipv4_nets = list(itertools.chain.from_iterable(ipv4_nets))
|
||||
# remove loopback
|
||||
ipv4_nets = [network for network in ipv4_nets if network['addr'] != '127.0.0.1']
|
||||
# remove auto conf
|
||||
ipv4_nets = [network for network in ipv4_nets if not network['addr'].startswith('169.254')]
|
||||
return ipv4_nets
|
||||
|
||||
|
||||
def local_ips():
|
||||
ipv4_nets = get_host_subnets()
|
||||
valid_ips = [network['addr'] for network in ipv4_nets]
|
||||
|
|
Loading…
Reference in New Issue