Skip to content
Snippets Groups Projects
Commit 31c272ef authored by gpotter2's avatar gpotter2
Browse files

Get ipv6 addresses using the pcap API

This will speed up the boot
parent 4e9f4e38
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ from scapy.config import conf
from scapy.utils import mac2str
from scapy.supersocket import SuperSocket
from scapy.error import Scapy_Exception, log_loading, warning
from scapy.pton_ntop import inet_ntop
import scapy.arch
import scapy.consts
......@@ -113,7 +114,7 @@ if conf.use_winpcapy:
pcap_freealldevs(devs)
if conf.use_winpcapy:
get_if_list = winpcapy_get_if_list
def in6_getifaddr():
def in6_getifaddr_raw():
err = create_string_buffer(PCAP_ERRBUF_SIZE)
devs = POINTER(pcap_if_t)()
ret = []
......@@ -128,7 +129,7 @@ if conf.use_winpcapy:
if a.contents.addr.contents.sa_family == socket.AF_INET6:
ap = a.contents.addr
val = cast(ap, POINTER(sockaddr_in6))
addr = socket.inet_ntop(socket.AF_INET6, str(val.contents.sin6_addr[:]))
addr = inet_ntop(socket.AF_INET6, "".join(chr(x) for x in val.contents.sin6_addr[:]))
scope = scapy.utils6.in6_getscope(addr)
ret.append((addr, scope, p.contents.name.decode('ascii')))
a = a.contents.next
......
......@@ -293,7 +293,7 @@ def get_windows_if_list():
# Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
# ---- -------------------- ------- ------ ---------- ---------
# Ethernet Killer E2200 Gigabit Ethernet Contro... 13 Up D0-50-99-56-DD-F9 1 Gbps
query = exec_query(['Get-NetAdapter -Physical'],
query = exec_query(['Get-NetAdapter'],
['InterfaceDescription', 'InterfaceIndex', 'Name',
'InterfaceGuid', 'MacAddress']) # It is normal that it is in this order
else:
......@@ -647,42 +647,13 @@ def in6_getifaddr():
"""
Returns all IPv6 addresses found on the computer
"""
if is_new_release():
ret = []
ps = sp.Popen([conf.prog.powershell, 'Get-NetRoute', '-AddressFamily IPV6', '|', 'select ifIndex, DestinationPrefix'], stdout = sp.PIPE, universal_newlines = True)
stdout, stdin = ps.communicate()
netstat_line = '\s+'.join(['(\d+)', ''.join(['([A-z|0-9|:]+)', '(\/\d+)'])])
pattern = re.compile(netstat_line)
for l in stdout.split('\n'):
match = re.search(pattern,l)
if match:
try:
if_index = match.group(1)
iface = dev_from_index(if_index)
except:
continue
scope = scapy.utils6.in6_getscope(match.group(2))
ret.append((match.group(2), scope, iface)) # (addr,scope,iface)
continue
return ret
else:
ret = []
# Get-WmiObject Win32_NetworkAdapterConfiguration | select InterfaceIndex, IpAddress
for line in exec_query(['Get-WmiObject', 'Win32_NetworkAdapterConfiguration'], ['InterfaceIndex', 'IPAddress']):
try:
iface = dev_from_index(line[0])
except:
continue
_l_addresses = line[1]
_inline = []
if _l_addresses:
_inline = _l_addresses[1:-1].split(",")
for _address in _inline:
_a = _address.strip()
if "." not in _a:
scope = scapy.utils6.in6_getscope(_a)
ret.append((_a, scope, iface)) # (addr,scope,iface)
return ret
ifaddrs = []
for ifaddr in in6_getifaddr_raw():
try:
ifaddrs.append((ifaddr[0], ifaddr[1], dev_from_pcapname(ifaddr[2])))
except ValueError:
pass
return ifaddrs
def _append_route6(routes, dpref, dp, nh, iface, lifaddr):
cset = [] # candidate set (possible source addresses)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment