orweis / winpcapy

A Modern Python wrapper for WinPcap
GNU General Public License v2.0
76 stars 23 forks source link

WinPcap - Open the right nic (Network Interface Card) #15

Open YoramT555 opened 5 years ago

YoramT555 commented 5 years ago

**Hi, I had on my computer 2 nics with same description. It could not distinguish between the two and opened always the first one. In winpcapy.py I saw it looks for match with the description only.

@classmethod
def get_matching_device(cls, glob=None):
    for name, description in cls.list_devices().items():
        if fnmatch.fnmatch(description, glob):
            return name, description
    return None, None

I've added a search with the name and left the search by description (for backward comparability purposes). Now you can look for your nic either with a name or with the description. Note that the name can includes the full GUID !!

@classmethod
def get_matching_device(cls, glob=None):
    for name, description in cls.list_devices().items():
        if fnmatch.fnmatch(name, glob) :
            return name, description
    for name, description in cls.list_devices().items():
        if fnmatch.fnmatch(description, glob):
            return name, description
    return None, None