^W$dZddlmZddlZddlmZmZddl m Z m Z iZ iZ Gdde ZGdde ZGd d e Zd Zd Zd ZdZedk(reyey)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_importlib_resources) Subscriber PublisherceZdZdZdZdZy) 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. ct|drt|dr||_nt|d|_tj|jd|_y)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_files 2/usr/lib/python3/dist-packages/netaddr/eui/ieee.py__init__zFileIndexer.__init__6sB :z *wz6/J DG:s+DGkk$''$? c:|jj|y)z Receives and writes index data to a CSV data file. :param data: record containing offset record information. N)rwriterow)rdatas rupdatezFileIndexer.updateDs T"rN)__name__ __module__ __qualname____doc__rrrrrr1s @#rrc(eZdZdZfdZdZxZS)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 ctt| t|drt|dr||_yt |d|_y)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. r r rbN)superr#rrrrr ieee_file __class__s rrzOUIIndexParser.__init__b: nd,. 9j )gi.HDG9d+DGrc d}d}d}td}td}td} |jj}|sn|r||vrd}|r)||vr|"|j||j |t |}|jj t |z }|jd} t| j||d} | |g}n|t |z }|j||j |y) z Starts the parsing process which detects records and notifies registered subscribers as it finds each OUI record. TNr(hex)-F) rrr appendnotifylenr splitintreplace) r skip_headerrecordsizemarkerhyphen empty_stringlineoffsetouiindexs rparsezOUIIndexParser.parseqs  W%S!"2 77##%Dv~# ~%MM$'KK'4y'',,.3t94jjl1oCKK =rBD !7<  d Frrrrr rr@ __classcell__r)s@rr#r#Ms( ,,rr#c(eZdZdZfdZdZxZS)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 ctt| t|drt|dr||_yt |d|_y)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. r r r%N)r&rErrrrr's rrzIABIndexParser.__init__r*rcd}d}d}td}td}td}td} |jj}|sn|r||vrd}|r)||vro|"|j||j ||jj t |z } |jd} | } | | g}t |}nr||vr`|t |z }|dj||} |jd} | j|d} t| | zd d z |d<n|t |z }|j||j |y) 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/ ) rrr r0r1r r2r3r5r4)rr6r7r8 hex_marker base16_markerr:r;r<r= iab_prefixr?prefixsuffixs rr@zIABIndexParser.parsesf   ) #K0 S!"2 77##%DzT1# T!%MM$'KK''',,.3t94!ZZ\!_ "4y$&D !**6<@af-a0 &"5"<q D !CH  d FrrArCs@rrErEs( ,3rrEch||}|jt||jy)z4Generate an index files from the IEEE registry file.N)attachrr@) registry_fh index_pathparser oui_parsers rcreate_index_from_registryrTs+ $Jk*-.rcttjtjtdtjtjtdt ttjtjtdtjtjtdt y)z1Create indices for OUI and IAB file based lookupszoui.txtoui.idxziab.txtiab.idxN)rT_pathjoindirname__file__r#rEr!rrcreate_indicesr\sv 5==*I6 5==*I6  5==*I6 5==*I6rc^ tj|Dcgc]}|jdc}D]G}|Dcgc] }t|c}\}}}|j |g||j ||fI |j ycc}wcc}w#|j wxYw)z/Load index from file into index data structure.zUTF-8N)rreaderdecoder4 setdefaultr0close)r?fpxrow_keyr=r8s r load_indexrgs;;2>a 1>? .C36"7a3q6"7 S&$   S" % #J  vtn - .  ?"7  s&BBBB 1B BB,ctttjtdtt tjtdy)z+Load OUI and IAB lookup indices into memoryrVrWN)rg OUI_INDEXr open_binary __package__ IAB_INDEXr!rr load_indicesrms2y.::; RSy.::; RSr__main__)r os.pathpathrXcsvrnetaddr.compatrr netaddr.corerrrirlrr#rErTr\rgrmrr!rrrts|4<.    #*#8PYPfWYWt T  zNr