Initial commit: mwhois with SCION AS support and decimal AS conversion

Based on mwhois by Antonios A. Chariton
Modifications for SCION AS support by Olaf Baumert, Axpo Systems AG
This commit is contained in:
Olaf Baumert
2025-06-03 11:01:02 +00:00
commit 34c631a06d
340 changed files with 212460 additions and 0 deletions

View File

@@ -0,0 +1,207 @@
=IEEE EUI-64 Tests=
Copyright (c) 2008-2015, David P. D. Moss. All rights reserved.
{{{
>>> from netaddr import *
}}}
IEEE EUI-64 tests.
{{{
>>> eui = EUI('00-1B-77-FF-FE-49-54-FD')
>>> eui
EUI('00-1B-77-FF-FE-49-54-FD')
>>> eui.oui
OUI('00-1B-77')
>>> eui.ei
'FF-FE-49-54-FD'
>>> eui.eui64()
EUI('00-1B-77-FF-FE-49-54-FD')
>>> mac = EUI('00-0F-1F-12-E7-33')
>>> ip = mac.ipv6_link_local()
>>> ip
IPAddress('fe80::20f:1fff:fe12:e733')
>>> ip.is_link_local()
True
>>> mac.eui64()
EUI('00-0F-1F-FF-FE-12-E7-33')
}}}
Individual Address Block tests.
{{{
>>> lower_eui = EUI('00-50-C2-05-C0-00')
>>> upper_eui = EUI('00-50-C2-05-CF-FF')
>>> lower_eui.is_iab()
True
>>> str(lower_eui.oui)
'00-50-C2'
>>> str(lower_eui.iab)
'00-50-C2-05-C0-00'
>>> lower_eui.ei
'05-C0-00'
>>> int(lower_eui.oui) == 0x0050c2
True
>>> int(lower_eui.iab) == 0x0050c205c
True
>>> upper_eui.is_iab()
True
>>> str(upper_eui.oui)
'00-50-C2'
>>> str(upper_eui.iab)
'00-50-C2-05-C0-00'
>>> upper_eui.ei
'05-CF-FF'
>>> int(upper_eui.oui) == 0x0050c2
True
>>> int(upper_eui.iab) == 0x0050c205c
True
}}}
Constructor tests.
{{{
>>> eui = EUI('00-90-96-AF-CC-39')
>>> eui == EUI('0-90-96-AF-CC-39')
True
>>> eui == EUI('00-90-96-af-cc-39')
True
>>> eui == EUI('00:90:96:AF:CC:39')
True
>>> eui == EUI('00:90:96:af:cc:39')
True
>>> eui == EUI('0090-96AF-CC39')
True
>>> eui == EUI('0090:96af:cc39')
True
>>> eui == EUI('009096-AFCC39')
True
>>> eui == EUI('009096:AFCC39')
True
>>> eui == EUI('009096AFCC39')
True
>>> eui == EUI('009096afcc39')
True
>>> EUI('01-00-00-00-00-00') == EUI('010000000000')
True
>>> EUI('01-00-00-00-00-00') == EUI('10000000000')
True
>>> EUI('01-00-00-01-00-00') == EUI('010000:010000')
True
>>> EUI('01-00-00-01-00-00') == EUI('10000:10000')
True
}}}
EUI-48 and EUI-64 indentifiers of the same value are *not* equivalent.
{{{
>>> eui48 = EUI('01-00-00-01-00-00')
>>> int(eui48) == 1099511693312
True
>>> eui64 = EUI('00-00-01-00-00-01-00-00')
>>> int(eui64) == 1099511693312
True
>>> eui48 == eui64
False
}}}
Sortability
{{{
>>> import random
>>> eui_list = [EUI(0, 64), EUI(0), EUI(0xffffffffffff, dialect=mac_unix), EUI(0x1000000000000)]
>>> random.shuffle(eui_list)
>>> eui_list.sort()
>>> for eui in eui_list:
... str(eui), eui.version
('00-00-00-00-00-00', 48)
('ff:ff:ff:ff:ff:ff', 48)
('00-00-00-00-00-00-00-00', 64)
('00-01-00-00-00-00-00-00', 64)
}}}
Persistence
{{{
>>> import pickle
>>> eui1 = EUI('00-00-00-01-02-03')
>>> eui2 = pickle.loads(pickle.dumps(eui1))
>>> eui1 == eui2
True
>>> eui1 = EUI('00-00-00-01-02-03', dialect=mac_cisco)
>>> eui2 = pickle.loads(pickle.dumps(eui1))
>>> eui1 == eui2
True
>>> eui1.dialect == eui2.dialect
True
>>> oui1 = EUI('00-00-00-01-02-03').oui
>>> oui2 = pickle.loads(pickle.dumps(oui1))
>>> oui1 == oui2
True
>>> oui1.records == oui2.records
True
>>> iab1 = EUI('00-50-C2-00-1F-FF').iab
>>> iab2 = pickle.loads(pickle.dumps(iab1))
>>> iab1 == iab2
True
>>> iab1.record == iab2.record
True
}}}

View File

@@ -0,0 +1,67 @@
=IEEE EUI-64 Identifier Tests=
Copyright (c) 2008-2015, David P. D. Moss. All rights reserved.
{{{
>>> from netaddr import *
}}}
Basic operations.
{{{
>>> mac = EUI('00-1B-77-49-54-FD')
>>> mac
EUI('00-1B-77-49-54-FD')
>>> eui = mac.eui64()
>>> eui
EUI('00-1B-77-FF-FE-49-54-FD')
>>> eui.eui64()
EUI('00-1B-77-FF-FE-49-54-FD')
>>> int(eui) == 7731765737772285
True
>>> eui.packed
b'\x00\x1bw\xff\xfeIT\xfd'
>>> eui.bin
'0b11011011101111111111111111110010010010101010011111101'
>>> eui.bits()
'00000000-00011011-01110111-11111111-11111110-01001001-01010100-11111101'
}}}
IPv6 interoperability
{{{
>>> mac = EUI('00-1B-77-49-54-FD')
>>> eui = mac.eui64()
>>> mac
EUI('00-1B-77-49-54-FD')
>>> eui
EUI('00-1B-77-FF-FE-49-54-FD')
>>> mac.modified_eui64()
EUI('02-1B-77-FF-FE-49-54-FD')
>>> mac.ipv6_link_local()
IPAddress('fe80::21b:77ff:fe49:54fd')
>>> eui.ipv6_link_local()
IPAddress('fe80::21b:77ff:fe49:54fd')
>>> mac.ipv6(0x12340000000000000000000000000000)
IPAddress('1234::21b:77ff:fe49:54fd')
>>> eui.ipv6(0x12340000000000000000000000000000)
IPAddress('1234::21b:77ff:fe49:54fd')

View File

@@ -0,0 +1,56 @@
=IEEE Publish/Subscribe Parser Tests=
Copyright (c) 2008-2015, David P. D. Moss. All rights reserved.
Basic OUIIndexParser and FileIndexer object tests.
{{{
>>> from netaddr.eui.ieee import OUIIndexParser, IABIndexParser, FileIndexer
>>> from io import StringIO
>>> infile = StringIO()
>>> outfile = StringIO()
>>> infile.write("""
... 00-CA-FE (hex) ACME CORPORATION
... 00CAFE (base 16) ACME CORPORATION
... 1 MAIN STREET
... SPRINGFIELD
... UNITED STATES
... """)
211
>>> infile.seek(0)
0
>>> iab_parser = OUIIndexParser(infile)
>>> iab_parser.attach(FileIndexer(outfile))
>>> iab_parser.parse()
>>> print(outfile.getvalue())
51966,1,210
<BLANKLINE>
}}}
Basic IABIndexParser and FileIndexer object tests.
{{{
>>> infile = StringIO()
>>> outfile = StringIO()
>>> infile.write("""
... 00-50-C2 (hex) ACME CORPORATION
... ABC000-ABCFFF (base 16) ACME CORPORATION
... 1 MAIN STREET
... SPRINGFIELD
... UNITED STATES
... """)
182
>>> infile.seek(0)
0
>>> iab_parser = IABIndexParser(infile)
>>> iab_parser.attach(FileIndexer(outfile))
>>> iab_parser.parse()
>>> print(outfile.getvalue())
84683452,1,181
<BLANKLINE>
}}}

View File

@@ -0,0 +1,258 @@
=EUI (MAC) Address Tutorial=
Copyright (c) 2008-2015, David P. D. Moss. All rights reserved.
{{{
>>> from netaddr import *
}}}
==Basic Operations==
This EUI object represents a MAC address.
{{{
>>> mac = EUI('00-1B-77-49-54-FD')
}}}
Standard repr() access returns a Python statement that can reconstruct the MAC address object from scratch if executed in the Python interpreter.
{{{
>>> mac
EUI('00-1B-77-49-54-FD')
}}}
Accessing the EUI object in the string context.
{{{
>>> str(mac)
'00-1B-77-49-54-FD'
>>> '%s' % mac
'00-1B-77-49-54-FD'
}}}
Here are a few other common properties.
{{{
>>> str(mac), str(mac.oui), mac.ei, mac.version
('00-1B-77-49-54-FD', '00-1B-77', '49-54-FD', 48)
}}}
==MAC Address Numerical Representations==
You can view an individual IP address in various other formats.
{{{
>>> int(mac) == 117965411581
True
>>> hex(mac)
'0x1b774954fd'
>>> oct(mac)
'0o1556722252375'
>>> mac.bits()
'00000000-00011011-01110111-01001001-01010100-11111101'
>>> mac.bin
'0b1101101110111010010010101010011111101'
}}}
==MAC Address Formatting==
It is very common to see MAC address in many different formats other than the standard IEEE EUI-48.
The EUI class constructor handles all these common forms.
{{{
>>> EUI('00-1B-77-49-54-FD')
EUI('00-1B-77-49-54-FD')
IEEE EUI-48 lowercase format.
>>> EUI('00-1b-77-49-54-fd')
EUI('00-1B-77-49-54-FD')
Common UNIX format.
>>> EUI('0:1b:77:49:54:fd')
EUI('00-1B-77-49-54-FD')
Cisco triple hextet format.
>>> EUI('001b:7749:54fd')
EUI('00-1B-77-49-54-FD')
>>> EUI('1b:7749:54fd')
EUI('00-1B-77-49-54-FD')
>>> EUI('1B:7749:54FD')
EUI('00-1B-77-49-54-FD')
Bare MAC addresses (no delimiters).
>>> EUI('001b774954fd')
EUI('00-1B-77-49-54-FD')
>>> EUI('01B774954FD')
EUI('00-1B-77-49-54-FD')
PostreSQL format (found in documentation).
>>> EUI('001B77:4954FD')
EUI('00-1B-77-49-54-FD')
}}}
It is equally possible to specify a selected format for your MAC string output in the form of a 'dialect' class. It's use is similar to the dialect class used in the Python standard library csv module.
{{{
>>> mac = EUI('00-1B-77-49-54-FD')
>>> mac
EUI('00-1B-77-49-54-FD')
>>> mac.dialect = mac_unix
>>> mac
EUI('0:1b:77:49:54:fd')
>>> mac.dialect = mac_unix_expanded
>>> mac
EUI('00:1b:77:49:54:fd')
>>> mac.dialect = mac_cisco
>>> mac
EUI('001b.7749.54fd')
>>> mac.dialect = mac_bare
>>> mac
EUI('001B774954FD')
>>> mac.dialect = mac_pgsql
>>> mac
EUI('001b77:4954fd')
}}}
You can of course, create your own dialect classes to customise the MAC formatting if the standard ones do not suit your needs.
Here's a tweaked UNIX MAC dialect that generates uppercase, zero-filled octets.
{{{
>>> class mac_custom(mac_unix): pass
>>> mac_custom.word_fmt = '%.2X'
>>> mac = EUI('00-1B-77-49-54-FD', dialect=mac_custom)
>>> mac
EUI('00:1B:77:49:54:FD')
}}}
==Looking Up EUI Organisational Data==
EUI objects provide an interface to the OUI (Organisationally Unique Identifier) and IAB (Individual Address Block) registration databases available from the IEEE.
Here is how you query an OUI with the EUI interface.
{{{
>>> mac = EUI('00-1B-77-49-54-FD')
>>> oui = mac.oui
>>> oui
OUI('00-1B-77')
>>> oui.registration().address
['Lot 8, Jalan Hi-Tech 2/3', 'Kulim Hi-Tech Park', 'Kulim Kedah 09000', 'MALAYSIA']
>>> oui.registration().org
'Intel Corporate'
}}}
You can also use OUI objects directly without going through the EUI interface.
A few OUI records have multiple registrations against them. I'm not sure if this is recording historical information or just a quirk of the IEEE reigstration process.
This example show you how you access them individually by specifying an index number.
{{{
>>> oui = OUI(524336) # OUI constructor accepts integer values too.
>>> oui
OUI('08-00-30')
>>> oui.registration(0).address
['2380 N. ROSE AVENUE', 'OXNARD CA 93010', 'UNITED STATES']
>>> oui.registration(0).org
'NETWORK RESEARCH CORPORATION'
>>> oui.registration(0).oui
'08-00-30'
>>> oui.registration(1).address
['CH-1211 GENEVE 23', 'SUISSE/SWITZ', 'SWITZERLAND']
>>> oui.registration(1).org
'CERN'
>>> oui.registration(1).oui
'08-00-30'
>>> oui.registration(2).address
['GPO BOX 2476V', 'MELBOURNE VIC 3001', 'AUSTRALIA']
>>> oui.registration(2).org
'ROYAL MELBOURNE INST OF TECH'
>>> oui.registration(2).oui
'08-00-30'
>>> for i in range(oui.reg_count):
... str(oui), oui.registration(i).org
...
('08-00-30', 'NETWORK RESEARCH CORPORATION')
('08-00-30', 'CERN')
('08-00-30', 'ROYAL MELBOURNE INST OF TECH')
}}}
Here is how you query an IAB with the EUI interface.
{{{
>>> mac = EUI('00-50-C2-00-0F-01')
>>> mac.is_iab()
True
>>> iab = mac.iab
>>> iab
IAB('00-50-C2-00-00-00')
>>> iab.registration()
{'address': ['1241 Superieor Ave E', 'Cleveland OH 44114', 'UNITED STATES'],
'iab': '00-50-C2-00-00-00',
...
'offset': 123,
'org': 'T.L.S. Corp.',
'size': 139}
}}}