Merge remote-tracking branch 'mdw/mdw/powm-sec'
[secnet] / ipaddrset-test.py
CommitLineData
6437945a
IJ
1#!/usr/bin/python
2
c215a4bc
IJ
3# This file is Free Software. It was originally written for secnet.
4#
5# Copyright 2014 Ian Jackson
6#
7# You may redistribute secnet as a whole and/or modify it under the
8# terms of the GNU General Public License as published by the Free
9# Software Foundation; either version 3, or (at your option) any
10# later version.
11#
12# You may redistribute this fileand/or modify it under the terms of
13# the GNU General Public License as published by the Free Software
14# Foundation; either version 2, or (at your option) any later version.
15# Note however that this version of ipaddrset.py uses the Python
16# ipaddr library from Google, which is licenced only under the Apache
17# Licence, version 2.0, which is only compatible with the GNU GPL v3
18# (or perhaps later versions), and not with the GNU GPL v2.
19#
20# This software is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this software; if not, see
27# https://www.gnu.org/licenses/gpl.html.
28#
29# The corresponding test vector file ise ipaddrset-test.expected. I
30# don't believe it is a creative work that attracts copyright. -iwj.
31
6437945a
IJ
32import ipaddr
33from ipaddr import IPNetwork, IPAddress
34
6437945a
IJ
35import ipaddrset
36from ipaddrset import IPAddressSet
37
38v4a=IPAddress('172.18.45.6')
39
40s=IPAddressSet()
41print 's =', s
42s.append([IPNetwork('172.18.45.0/24')])
43s.append([IPNetwork('2001:23:24::/40')])
44print s
45
46t=IPAddressSet(map(IPNetwork,['172.31.80.8/32','172.18.45.192/28']))
47print 't =', t
48print t <= s
49print t == s
50
51for n1s in ['172.18.44.0/23','172.18.45.6/32','172.18.45.0/24']:
52 n1=IPNetwork(n1s)
53 print n1
54 print s.contains(n1)
55 print t.contains(n1)
56
57n=s.networks()[0]
58
59a=ipaddrset.complete_set()
60print 'a =', a
61print a >= s
62print a >= t
63
64print '^'
65print s.intersection(t)
66print t.intersection(s)
67
68print 'u'
69print s.union(t)
70print t.union(s)