New issue 48 by thelonelywolf: network recognition
http://code.google.com/p/netaddr/issues/detail?id=48
Hi
before all thanks for your commit #337 :P
Sorry for the question, i've tried to search within documentation without
success, however, let's say we have 2 (or more) different ip address:
192.168.0.1 and 192.168.1.6
Is there any way/method that return something like: "this 2 address belongs
to two different networks"?
Thanks for your attention :)
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
you could find the supernets of each and the find the union of those sets.
something like
In [12]: addr1 = netaddr.IPNetwork('192.168.0.1')
In [13]: addr2 = netaddr.IPNetwork('192.168.1.6')
In [14]: set.union(set(addr1.supernet()), set(addr2.supernet()))
Out[15]: set([IPNetwork('192.128.0.0/9'), IPNetwork('192.0.0.0/6'),
IPNetwork('192.128.0.0/10'), IPNetwork('192.0.0.0/5'),
IPNetwork('192.168.0.0/16'), IPNetwork('192.168.1.0/29'),
IPNetwork('192.168.0.0/26'), IPNetwork('192.168.0.0/22'),
IPNetwork('192.168.0.0/31'), IPNetwork('192.168.0.0/18'),
IPNetwork('192.168.0.0/14'), IPNetwork('192.168.0.0/29'),
IPNetwork('128.0.0.0/1'), IPNetwork('192.168.0.0/17'),
IPNetwork('192.0.0.0/7'), IPNetwork('192.160.0.0/11'),
IPNetwork('192.168.1.0/27'), IPNetwork('192.168.0.0/15'),
IPNetwork('192.168.0.0/20'), IPNetwork('192.168.1.6/31'),
IPNetwork('192.160.0.0/12'), IPNetwork('192.168.1.0/24'),
IPNetwork('192.168.0.0/25'), IPNetwork('192.0.0.0/8'),
IPNetwork('192.168.1.4/30'), IPNetwork('192.0.0.0/2'),
IPNetwork('0.0.0.0/0'), IPNetwork('192.168.0.0/24'),
IPNetwork('192.168.0.0/23'), IPNetwork('192.168.0.0/28'),
IPNetwork('192.0.0.0/4'), IPNetwork('192.168.1.0/28'),
IPNetwork('192.168.0.0/19'), IPNetwork('192.168.0.0/30'),
IPNetwork('192.168.1.0/25'), IPNetwork('192.0.0.0/3'),
IPNetwork('192.168.0.0/13'), IPNetwork('192.168.0.0/27'),
IPNetwork('192.168.0.0/21'), IPNetwork('192.168.1.0/26')])
hm, I take that back. that doesn't seem right. nevermind.
ah, intersection was what I was thinking of.
(sorted, for cleanliness)
In [18]: sorted(set.intersection(set(addr1.supernet()),
set(adr2.supernet())))
Out[18]:
[IPNetwork('0.0.0.0/0'),
IPNetwork('128.0.0.0/1'),
IPNetwork('192.0.0.0/2'),
IPNetwork('192.0.0.0/3'),
IPNetwork('192.0.0.0/4'),
IPNetwork('192.0.0.0/5'),
IPNetwork('192.0.0.0/6'),
IPNetwork('192.0.0.0/7'),
IPNetwork('192.0.0.0/8'),
IPNetwork('192.128.0.0/9'),
IPNetwork('192.128.0.0/10'),
IPNetwork('192.160.0.0/11'),
IPNetwork('192.160.0.0/12'),
IPNetwork('192.168.0.0/13'),
IPNetwork('192.168.0.0/14'),
IPNetwork('192.168.0.0/15'),
IPNetwork('192.168.0.0/16'),
IPNetwork('192.168.0.0/17'),
IPNetwork('192.168.0.0/18'),
IPNetwork('192.168.0.0/19'),
IPNetwork('192.168.0.0/20'),
IPNetwork('192.168.0.0/21'),
IPNetwork('192.168.0.0/22'),
IPNetwork('192.168.0.0/23')]