Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
B

¼±I‰šÉw@ã@sdZddlmZddlmZddlZddlZddlZddlZy(ddl	m
Z
ddl	mZddl	mZWn8e
k
rœddlm
Z
ddlmZddlmZYnXyddlmZWn e
k
rÎddlmZYnXddlZddlZed	d
ddgƒZGd
d„deƒZdd„ZedkreƒdS)zŠParser library for Wireshark's OUI database.

Converts MAC addresses into a manufacturer using Wireshark's OUI database.

See README.md.

é)Úprint_function)Ú
namedtupleN)ÚRequest)Úurlopen)ÚURLError)ÚStringIOÚVendorÚmanufÚ
manuf_longÚcommentc@s’eZdZdZdZdZd!dd„Zd"dd	„Zd#dd„Zd$dd„Z	dd„Z
dd„Zdd„Zdd„Z
dd„Ze d¡Zdd„Zedd„ƒZedd „ƒZdS)%Ú	MacParserašClass that contains a parser for Wireshark's OUI database.

    Optimized for quick lookup performance by reading the entire file into memory on
    initialization. Maps ranges of MAC addresses to manufacturers and comments (descriptions).
    Contains full support for netmasks and other strange things in the database.

    See https://www.wireshark.org/tools/oui-lookup.html

    Args:
        manuf_name (str): Location of the manuf database file. Defaults to "manuf" in the same
            directory.
        update (bool): Whether to update the manuf file automatically. Defaults to False.

    Raises:
        IOError: If manuf file could not be found.

    z7https://gitlab.com/wireshark/wireshark/raw/master/manufzKhttps://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=wkaNFcCs(|p
| ¡|_|r| ¡n| ¡dS)N)Úget_packaged_manuf_file_pathÚ_manuf_nameÚupdateÚrefresh)ÚselfÚ
manuf_namer©rú‰/build/wlanpi-profiler-koocPu/wlanpi-profiler-1.0.8/debian/wlanpi-profiler/opt/wlanpi-profiler/lib/python3.7/site-packages/manuf/manuf.pyÚ__init__Cs
zMacParser.__init__c
	Csb|s
|j}tj|ddd}t| ¡ƒ}WdQRXi|_x|D]}yò| ¡}|r`|ddkrbw@| dd¡}d	d
„| d¡Dƒ}|d d¡}| 	|d¡}| 
|¡}| |¡}	t|ƒdkrÚd
t
|dƒ}
|
|	krÚ|
}	t|ƒdkrø|d d¡ ¡nd}t|ƒdkr|dnd}t|d||d|j|	||	?f<Wq@td|ƒ‚Yq@Xq@W| ¡dS)a$Refresh/reload manuf database. Call this when manuf file is updated.

        Args:
            manuf_name (str): Location of the manuf data base file. Defaults to "manuf" in the
                same directory.

        Raises:
            IOError: If manuf file could not be found.

        Úrzutf-8)ÚencodingNrú#z		ú	cSsg|]}| ¡‘qSr)Ústrip)Ú.0Úfieldrrrú
<listcomp>bsz%MacParser.refresh.<locals>.<listcomp>ú/éé0éé)r	r
rzCouldn't parse line)rÚioÚopenrÚreadÚ_masksrÚreplaceÚsplitÚ
_strip_macÚ_get_mac_intÚ
_bits_leftÚlenÚintrÚprintÚclose)
rrÚ	read_fileZ
manuf_fileÚlineÚfieldsÚpartsÚmac_strÚmac_intÚmaskZ	mask_specrZ	long_namerrrrJs6

"$
zMacParser.refreshTc	CsZ|s
|j}|s|j}ytt|ddidƒ}Wntk
rHtdƒ‚YnX|jdkrˆt|dƒ}| | ¡¡WdQRX|r¦| 	|¡nd 
|j|j¡}td	 
|¡ƒ‚| ¡|s¸|j
}ytt|ddidƒ}Wntk
rìtd
ƒ‚YnX|jdkr0t|dƒ}| | ¡¡WdQRX|rN| 	|¡nd 
|j|j¡}td	 
|¡ƒ‚| ¡dS)aUpdate the Wireshark OUI database to the latest version.

        Args:
            manuf_url (str): URL pointing to OUI database. Defaults to database located at
                code.wireshark.org.
            manuf_name (str): Location to store the new OUI database. Defaults to "manuf" in the
                same directory.
            refresh (bool): Refresh the database once updated. Defaults to True. Uses database
                stored at manuf_name.

        Raises:
            URLError: If the download fails

        z
User-AgentZMozilla)ÚheaderszFailed downloading OUI databaseéÈÚwbNz{0} {1}z Failed downloading database: {0}zFailed downloading WFA databaseÚab)Ú	MANUF_URLrrrrÚcoder$Úwriter%rÚformatÚmsgr/ÚWFA_URL)rZ	manuf_urlZwfa_urlrrÚresponseÚ
write_fileÚerrrrrrzs<
zMacParser.updatercCsrg}|dkr|S| |¡}| |¡}xHt| |¡dƒD]4}|j |||?f¡}|r6| |¡t|ƒ|kr6Pq6W|S)a¿Search for multiple Vendor tuples possibly matching a MAC address.

        Args:
            mac (str): MAC address in standard format.
            maximum (int): Maximum results to return. Defaults to 1.

        Returns:
            List of Vendor namedtuples containing (manuf, comment), with closest result first. May
            be empty if no results found.

        Raises:
            ValueError: If the MAC could not be parsed.

        rr )r)r*Úranger+r&ÚgetÚappendr,)rÚmacÚmaximumÚvendorsr4r5r6ÚresultrrrÚsearch´s


zMacParser.searchcCs,| |¡}t|ƒdkr$tddddS|dS)aeGet a Vendor tuple containing (manuf, comment) from a MAC address.

        Args:
            mac (str): MAC address in standard format.

        Returns:
            Vendor: Vendor namedtuple containing (manuf, comment). Either or both may be None if
            not found.

        Raises:
            ValueError: If the MAC could not be parsed.

        rN)r	r
r)rKr,r)rrGrIrrrÚget_allÒs
zMacParser.get_allcCs| |¡jS)aReturns manufacturer from a MAC address.

        Args:
            mac (str): MAC address in standard format.

        Returns:
            string: String containing manufacturer, or None if not found.

        Raises:
            ValueError: If the MAC could not be parsed.

        )rLr	)rrGrrrÚ	get_manufås
zMacParser.get_manufcCs| |¡jS)a'Returns manufacturer long name from a MAC address.

        Args:
            mac (str): MAC address in standard format.

        Returns:
            string: String containing manufacturer, or None if not found.

        Raises:
            ValueError: If the MAC could not be parsed.

        )rLr
)rrGrrrÚget_manuf_longôs
zMacParser.get_manuf_longcCs| |¡jS)aReturns comment from a MAC address.

        Args:
            mac (str): MAC address in standard format.

        Returns:
            string: String containing comment, or None if not found.

        Raises:
            ValueError: If the MAC could not be parsed.

        )rLr)rrGrrrÚget_comments
zMacParser.get_commentcCs<yt|dƒ| |¡>Stk
r6td |¡ƒ‚YnXdS)NézCould not parse MAC: {0})r-r+Ú
ValueErrorr>)rr4rrrr*szMacParser._get_mac_intz[-:\.]cCs|j d|¡S)NÚ)Ú_patternÚsub)rrGrrrr)szMacParser._strip_maccCsddt|ƒS)Nr é)r,)r4rrrr+"szMacParser._bits_leftcCsLtdkstdkrt}nt t¡j}tj tj |tj¡¡}tj |d¡}|S)z[
        returns the path to manuf file bundled with the package.
        :return:
        NrRr	)	Ú__package__Ú__file__Ú	importlibÚ
import_moduleÚosÚpathÚabspathÚjoinÚpardir)Zpackage_init_pathÚpackage_pathZmanuf_file_pathrrrr
&sz&MacParser.get_packaged_manuf_file_path)NF)N)NNNT)r)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r;r@rrrrKrLrMrNrOr*ÚreÚcompilerSr)Ústaticmethodr+r
rrrrr.s 

0
:

rcGsŠtjdd}|jdddddd|jd	d
ddd
|jdddd|pHd}|j|d}t|j|jd}|jr|t| 	|j¡ƒt
 d¡dS)z+Simple command line wrapping for MacParser.z,Parser utility for Wireshark's OUI database.)Údescriptionz-mz--manufzKmanuf file path. Defaults to manuf file packaged with manuf.py installationÚstoreN)ÚhelpÚactionÚdefaultz-uz--updatez#update manuf file from the internetÚ
store_true)rirjÚmac_addressú?zMAC address to check)Únargsri)Úargs)rrr)ÚargparseÚArgumentParserÚadd_argumentÚ
parse_argsrr	rrmr.rLÚsysÚexit)Z
input_argsZ	argparserrpÚparserrrrÚmain5srxÚ__main__)rcÚ
__future__rÚcollectionsrrqrdrur#Úurllib2rrrÚImportErrorÚurllib.requestÚurllib.errorrrXrZrÚobjectrrxr`rrrrÚ<module>s6