def _in6_getifaddr(ifname): """ Returns a list of IPv6 addresses configured on the interface ifname. """ # Get the output of ifconfig try: f = os.popen("%s %s" % (conf.prog.ifconfig, ifname)) except OSError as msg: log_interactive.warning("Failed to execute ifconfig.") return [] # Iterate over lines and extract IPv6 addresses ret = [] for line in f: if "inet6" in line: addr = line.rstrip().split(None, 2)[1] # The second element is the IPv6 address else: continue if '%' in line: # Remove the interface identifier if present addr = addr.split("%", 1)[0] # Check if it is a valid IPv6 address try: socket.inet_pton(socket.AF_INET6, addr) except: continue # Get the scope and keep the address scope = in6_getscope(addr) ret.append((addr, scope, ifname)) return ret
def _in6_getifaddr(ifname): """ Returns a list of IPv6 addresses configured on the interface ifname. """ # Get the output of ifconfig try: f = os.popen("%s %s" % (conf.prog.ifconfig, ifname)) except OSError: log_interactive.warning("Failed to execute ifconfig.") return [] # Iterate over lines and extract IPv6 addresses ret = [] for line in f: if "inet6" in line: addr = line.rstrip().split( None, 2)[1] # The second element is the IPv6 address # noqa: E501 else: continue if '%' in line: # Remove the interface identifier if present addr = addr.split("%", 1)[0] # Check if it is a valid IPv6 address try: socket.inet_pton(socket.AF_INET6, addr) except Exception: continue # Get the scope and keep the address scope = in6_getscope(addr) ret.append((addr, scope, ifname)) return ret
def in6_getifaddr(): """ Returns all IPv6 addresses found on the computer """ ifaddrs = [] ip6s = get_ips(v6=True) for iface in ip6s: ips = ip6s[iface] for ip in ips: scope = in6_getscope(ip) ifaddrs.append((ip, scope, iface)) # Appends Npcap loopback if available if conf.use_npcap and scapy.consts.LOOPBACK_INTERFACE: ifaddrs.append(("::1", 0, scapy.consts.LOOPBACK_INTERFACE)) return ifaddrs
if "inet6" in line: # The second element is the IPv6 address addr = line.rstrip().split(None, 2)[1] else: continue if '%' in line: # Remove the interface identifier if present addr = addr.split("%", 1)[0] # Check if it is a valid IPv6 address try: socket.inet_pton(socket.AF_INET6, addr) except: continue # Get the scope and keep the address scope = in6_getscope(addr) ret.append((addr, scope, ifname)) return ret def in6_getifaddr(): """ Returns a list of 3-tuples of the form (addr, scope, iface) where 'addr' is the address of scope 'scope' associated to the interface 'iface'. This is the list of all addresses of all interfaces available on the system. """
for line in f: if "inet6" in line: addr = line.rstrip().split(None, 2)[1] # The second element is the IPv6 address else: continue if '%' in line: # Remove the interface identifier if present addr = addr.split("%", 1)[0] # Check if it is a valid IPv6 address try: socket.inet_pton(socket.AF_INET6, addr) except: continue # Get the scope and keep the address scope = in6_getscope(addr) ret.append((addr, scope, ifname)) return ret def in6_getifaddr(): """ Returns a list of 3-tuples of the form (addr, scope, iface) where 'addr' is the address of scope 'scope' associated to the interface 'iface'. This is the list of all addresses of all interfaces available on the system. """ # List all network interfaces