o inh'$@sdZddlmZddlZddlmZmZddl m Z m Z iZ iZ Gddde ZGddde ZGd d d e Zd d Zd dZddZddZedkrQedSedS)z Provides access to public OUI and IAB registration data published by the IEEE. More details can be found at the following URLs :- - IEEE Home Page - http://www.ieee.org/ - Registration Authority Home Page - http://standards.ieee.org/regauth/ N) _bytes_type _open_binary) Subscriber Publisherc@s eZdZdZddZddZdS) FileIndexerz A concrete Subscriber that receives OUI record offset information that is written to an index data file as a set of comma separated records. cCs>t|drt|dr||_nt|d|_tj|jdd|_dS)z Constructor. :param index_file: a file-like object or name of index file where index records will be written. readlinetellw )lineterminatorN)hasattrfhopen_csvwriter)self index_filer;/usr/local/lib/python3.10/dist-packages/netaddr/eui/ieee.py__init__6s zFileIndexer.__init__cCs|j|dS)z Receives and writes index data to a CSV data file. :param data: record containing offset record information. N)rwriterow)rdatarrrupdateDszFileIndexer.updateN)__name__ __module__ __qualname____doc__rrrrrrr1s rc(eZdZdZfddZddZZS)OUIIndexParsera A concrete Publisher that parses OUI (Organisationally Unique Identifier) records from IEEE text-based registration files It notifies registered Subscribers as each record is encountered, passing on the record's position relative to the start of the file (offset) and the size of the record (in bytes). The file processed by this parser is available online from this URL :- - http://standards.ieee.org/regauth/oui/oui.txt This is a sample of the record structure expected:: 00-CA-FE (hex) ACME CORPORATION 00CAFE (base 16) ACME CORPORATION 1 MAIN STREET SPRINGFIELD UNITED STATES c<tt|t|drt|dr||_dSt|d|_dS)z Constructor. :param ieee_file: a file-like object or name of file containing OUI records. When using a file-like object always open it in binary mode otherwise offsets will probably misbehave. rrrbN)superrrr r rr ieee_file __class__rrrb zOUIIndexParser.__init__c Csd}d}d}td}td}td} |j}|snE|r#||vr#d}|r&q||vrY|dur8||||t|}|jt|}|d} t| ||d} | |g}n|t|7}q||||dS) z Starts the parsing process which detects records and notifies registered subscribers as it finds each OUI record. TNr(hex)-F) rr rappendnotifylenrsplitintreplace) r skip_headerrecordsizemarkerhyphen empty_stringlineoffsetouiindexrrrparseqs6        zOUIIndexParser.parserrrrrr; __classcell__rrr$rrM rcr)IABIndexParsera A concrete Publisher that parses IAB (Individual Address Block) records from IEEE text-based registration files It notifies registered Subscribers as each record is encountered, passing on the record's position relative to the start of the file (offset) and the size of the record (in bytes). The file processed by this parser is available online from this URL :- - http://standards.ieee.org/regauth/oui/iab.txt This is a sample of the record structure expected:: 00-50-C2 (hex) ACME CORPORATION ABC000-ABCFFF (base 16) ACME CORPORATION 1 MAIN STREET SPRINGFIELD UNITED STATES cr)z Constructor. :param ieee_file: a file-like object or name of file containing IAB records. When using a file-like object always open it in binary mode otherwise offsets will probably misbehave. rrr N)r!r?rr r rr"r$rrrr&zIABIndexParser.__init__cCs(d}d}d}td}td}td}td} |j}|sni|r'||vr'd}|r*q||vrV|dur<|||||jt|} |d} | } | | g}t|}n1||vr|t|7}|d||} |d} | |d} t | | d d ?|d<n|t|7}q||||dS) z Starts the parsing process which detects records and notifies registered subscribers as it finds each IAB record. TNrr'z (base 16)r(r)Fr* ) rr rr+r,rr-r.r0r/)rr1r2r3 hex_marker base16_markerr5r6r7r8 iab_prefixr:prefixsuffixrrrr;sD          $zIABIndexParser.parser<rrr$rr?r>r?cCs"||}|t||dS)z4Generate an index files from the IEEE registry file.N)attachrr;) registry_fh index_pathparser oui_parserrrrcreate_index_from_registrys rKcCsTttttdtttdtttttdtttdtdS)z1Create indices for OUI and IAB file based lookupszoui.txtoui.idxziab.txtiab.idxN)rK_pathjoindirname__file__rr?rrrrcreate_indicessrRcCsfz-tdd|DD]}dd|D\}}}||g||||fq W|dS|w)z/Load index from file into index data structure.cSsg|]}|dqS)zUTF-8)decode).0xrrr szload_index..cSsg|]}t|qSr)r/)rT_rrrrVsN)rreader setdefaultr+close)r:fprowkeyr8r3rrr load_indexs r^cCs$ttttdttttddS)z+Load OUI and IAB lookup indices into memoryrLrMN)r^ OUI_INDEXr __package__ IAB_INDEXrrrr load_indicessrb__main__)ros.pathpathrNcsvrnetaddr.compatrr netaddr.corerrr_rarrr?rKrRr^rbrrrrrs" SZ