fixed util.get_address() when VPN is not present
This commit is contained in:
parent
4fc654c6b6
commit
1a604ca2f3
20
util.py
20
util.py
@ -30,13 +30,21 @@ def get_address(interface={"tun0", "vpn0"}):
|
|||||||
# not found or not specified, take the first available, which is not loopback
|
# not found or not specified, take the first available, which is not loopback
|
||||||
if not interface in ni.interfaces():
|
if not interface in ni.interfaces():
|
||||||
interfaces = ni.interfaces()
|
interfaces = ni.interfaces()
|
||||||
interfaces.remove('lo')
|
for interface in interfaces:
|
||||||
interface = interfaces[0]
|
if interface == "lo":
|
||||||
|
continue
|
||||||
|
addresses = ni.ifaddresses(interface)
|
||||||
|
addresses = [addresses[ni.AF_INET][i]["addr"] for i in range(len(addresses[ni.AF_INET]))]
|
||||||
|
addresses = [addr for addr in addresses if not str(addr).startswith("127")]
|
||||||
|
if addresses:
|
||||||
|
return addresses[0]
|
||||||
|
|
||||||
addresses = ni.ifaddresses(interface)
|
print("[-] Could not find a network interface card with a valid ipv4")
|
||||||
addresses = [addresses[ni.AF_INET][i]["addr"] for i in range(len(addresses[ni.AF_INET]))]
|
else:
|
||||||
addresses = [addr for addr in addresses if not str(addr).startswith("127")]
|
addresses = ni.ifaddresses(interface)
|
||||||
return addresses[0]
|
addresses = [addresses[ni.AF_INET][i]["addr"] for i in range(len(addresses[ni.AF_INET]))]
|
||||||
|
addresses = [addr for addr in addresses if not str(addr).startswith("127")]
|
||||||
|
return addresses[0]
|
||||||
|
|
||||||
def generate_random_string(length=16, charset=string.printable):
|
def generate_random_string(length=16, charset=string.printable):
|
||||||
chars = random.choices(charset, k=length)
|
chars = random.choices(charset, k=length)
|
||||||
|
Loading…
Reference in New Issue
Block a user