forked from p34709852/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,14 +9,8 @@ import netifaces
|
|||
from subprocess import check_output
|
||||
from random import randint
|
||||
|
||||
if sys.platform == "win32":
|
||||
|
||||
def local_ips():
|
||||
local_hostname = socket.gethostname()
|
||||
return socket.gethostbyname_ex(local_hostname)[2]
|
||||
|
||||
|
||||
def get_host_subnets():
|
||||
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)
|
||||
|
@ -27,9 +21,19 @@ if sys.platform == "win32":
|
|||
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():
|
||||
local_hostname = socket.gethostname()
|
||||
return socket.gethostbyname_ex(local_hostname)[2]
|
||||
|
||||
|
||||
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