mirror of
https://git.photon.obnh.io/AXSY/whois.git
synced 2026-03-12 18:01:32 +00:00
Based on mwhois by Antonios A. Chariton Modifications for SCION AS support by Olaf Baumert, Axpo Systems AG
72 lines
2.1 KiB
Plaintext
72 lines
2.1 KiB
Plaintext
=IP Matching Tests=
|
|
|
|
Copyright (c) 2008-2015, David P. D. Moss. All rights reserved.
|
|
|
|
{{{
|
|
|
|
>>> from netaddr import *
|
|
|
|
>>> largest_matching_cidr('192.0.2.0', ['192.0.2.0'])
|
|
IPNetwork('192.0.2.0/32')
|
|
|
|
>>> largest_matching_cidr('192.0.2.0', ['10.0.0.1', '192.0.2.0'])
|
|
IPNetwork('192.0.2.0/32')
|
|
|
|
>>> largest_matching_cidr('192.0.2.0', ['10.0.0.1', '192.0.2.0', '224.0.0.1'])
|
|
IPNetwork('192.0.2.0/32')
|
|
|
|
>>> smallest_matching_cidr('192.0.2.0', ['10.0.0.1', '192.0.2.0', '224.0.0.1'])
|
|
IPNetwork('192.0.2.0/32')
|
|
|
|
>>> smallest_matching_cidr('192.0.2.32', ['0.0.0.0/0', '10.0.0.0/8', '192.0.0.0/8', '192.0.1.0/24', '192.0.2.0/24', '192.0.3.0/24'])
|
|
IPNetwork('192.0.2.0/24')
|
|
|
|
>>> all_matching_cidrs('192.0.2.32', ['0.0.0.0/0', '10.0.0.0/8', '192.0.0.0/8', '192.0.1.0/24', '192.0.2.0/24', '192.0.3.0/24'])
|
|
[IPNetwork('0.0.0.0/0'), IPNetwork('192.0.0.0/8'), IPNetwork('192.0.2.0/24')]
|
|
|
|
>>> smallest_matching_cidr('192.0.2.0', ['10.0.0.1', '224.0.0.1'])
|
|
|
|
>>> largest_matching_cidr('192.0.2.0', ['10.0.0.1', '224.0.0.1'])
|
|
|
|
>>> networks = [str(c) for c in IPNetwork('192.0.2.128/27').supernet(22)]
|
|
|
|
>>> networks
|
|
['192.0.0.0/22', '192.0.2.0/23', '192.0.2.0/24', '192.0.2.128/25', '192.0.2.128/26']
|
|
|
|
>>> all_matching_cidrs('192.0.2.0', networks)
|
|
[IPNetwork('192.0.0.0/22'), IPNetwork('192.0.2.0/23'), IPNetwork('192.0.2.0/24')]
|
|
|
|
>>> smallest_matching_cidr('192.0.2.0', networks)
|
|
IPNetwork('192.0.2.0/24')
|
|
|
|
>>> largest_matching_cidr('192.0.2.0', networks)
|
|
IPNetwork('192.0.0.0/22')
|
|
|
|
}}}
|
|
|
|
Checking matches with varying IP address versions.
|
|
|
|
{{{
|
|
>>> all_matching_cidrs('192.0.2.0', ['192.0.2.0/24'])
|
|
[IPNetwork('192.0.2.0/24')]
|
|
|
|
>>> all_matching_cidrs('192.0.2.0', ['::/96'])
|
|
[]
|
|
|
|
>>> all_matching_cidrs('::ffff:192.0.2.1', ['::ffff:192.0.2.0/96'])
|
|
[IPNetwork('::ffff:192.0.2.0/96')]
|
|
|
|
>>> all_matching_cidrs('::192.0.2.1', ['::192.0.2.0/96'])
|
|
[IPNetwork('::192.0.2.0/96')]
|
|
|
|
>>> all_matching_cidrs('::192.0.2.1', ['192.0.2.0/23'])
|
|
[]
|
|
|
|
>>> all_matching_cidrs('::192.0.2.1', ['192.0.2.0/24', '::192.0.2.0/120'])
|
|
[IPNetwork('::192.0.2.0/120')]
|
|
|
|
>>> all_matching_cidrs('::192.0.2.1', [IPNetwork('192.0.2.0/24'), IPNetwork('::192.0.2.0/120')])
|
|
[IPNetwork('::192.0.2.0/120')]
|
|
|
|
}}}
|