Skip to content

get_if_list() in Python 3.7 on Windows 10 returns a list that is missing "\Device\NPF_" #3891

@paullangner

Description

@paullangner

Brief description

The get_if_list() function returns the ServiceName of the interface - i.e. {0CE49FA1-F518-4311-9ABE-09A7B2A01ED9} from the windows registry, but in order to use this name with any of the other functions - such as get_if_hwaddr(), it needs to have \Device\NPF_ prepended to it - i.e. \Device\NPF_{0CE49FA1-F518-4311-9ABE-09A7B2A01ED9}. To be consistent, get_if_list() should either return the list with this prepended to the name, or the other functions should accept the ServiceName.

This exercise was prompted by trying to get an interface with a specific MAC address, and it would be nice if there was a dev_from_hwaddr() function available, as USB Ethernet adapters tend to move around if they get plugged into different USB ports.

Scapy version

2.5.0

Python version

3.7

Operating system

Windows 10

Additional environment information

No response

How to reproduce

#!/usr/bin/python
from scapy.all import *
import struct

interfaceList = get_if_list()

this does not work - MAC addresses are all zero

for i in range(len(interfaceList)):
fullInterfaceName = interfaceList[i]
macAddress = get_if_hwaddr (fullInterfaceName)
print (F"Interface #{i} = {fullInterfaceName} - MAC address = {macAddress}")

this works and returns the correct MAC addresses

print ("")
for i in range(len(interfaceList)):
fullInterfaceName = "\Device\NPF_"+interfaceList[i]
macAddress = get_if_hwaddr (fullInterfaceName)
print (F"Interface #{i} = {fullInterfaceName} - MAC address = {macAddress}")

Actual result

C:\Users\lab1\ptp>python interfaceListExample.py
Interface #0 = {1BAD53D5-83AE-4F62-99D1-D316438A5824} - MAC address = 00:00:00:00:00:00
Interface #1 = {5EBD68EB-B670-4AC3-812A-09FC2CF16375} - MAC address = 00:00:00:00:00:00
Interface #2 = {8CE23EFF-B25D-4F29-A360-D004E50056F0} - MAC address = 00:00:00:00:00:00
Interface #3 = {0CE49FA1-F518-4311-9ABE-09A7B2A01ED9} - MAC address = 00:00:00:00:00:00
Interface #4 = {A1088F5D-F4A8-4E10-A8BB-18EBA16C1588} - MAC address = 00:00:00:00:00:00
Interface #5 = {EA554A36-92C0-4F06-BD1A-76E10FB8F788} - MAC address = 00:00:00:00:00:00
Interface #6 = \Device\NPF_Loopback - MAC address = 00:00:00:00:00:00

Interface #0 = \Device\NPF_{1BAD53D5-83AE-4F62-99D1-D316438A5824} - MAC address = 00:00:00:00:00:00
Interface #1 = \Device\NPF_{5EBD68EB-B670-4AC3-812A-09FC2CF16375} - MAC address = 00:00:00:00:00:00
Interface #2 = \Device\NPF_{8CE23EFF-B25D-4F29-A360-D004E50056F0} - MAC address = 00:00:00:00:00:00
Interface #3 = \Device\NPF_{0CE49FA1-F518-4311-9ABE-09A7B2A01ED9} - MAC address = f8:e4:3b:9e:19:62
Interface #4 = \Device\NPF_{A1088F5D-F4A8-4E10-A8BB-18EBA16C1588} - MAC address = f8:e4:3b:9e:13:ba
Interface #5 = \Device\NPF_{EA554A36-92C0-4F06-BD1A-76E10FB8F788} - MAC address = 8c:ec:4b:96:47:39
Interface #6 = \Device\NPF_\Device\NPF_Loopback - MAC address = 00:00:00:00:00:00

Expected result

Good and bad results are shown above

Related resources

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions