ipaddress is available in python3 and ipaddr is not.
Code changes:
- Change the imports and references to the module name
- IPNetwork & IPAddress functions => ip_address & ip_network
- There is no IPNetwork superclass so don't mention it in docstrings
- collapse_address_list => collapse_addresses
- There is no version parameter to ip_address; we have to
switch on v ourselves and call IPv6Address or IPv4Address
Administrivia:
- Update debian/control and INSTALL.
- Remove references to ipaddr's licence. ipaddress is under
the same licence as python so does not need special mention.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
You will probably be using the supplied `make-secnet-sites' program to
generate your VPN's list of sites as a secnet configuration from a
more-human-writeable form. If so you need to install the standard
-`future' and `ipaddr' Python modules (python-future and python-ipaddr
-on Debian-derived systems).
+`future' and `ipaddress' Python modules (python-future and
+python-ipaddress on Debian-derived systems).
** System and network configuration
Uploaders: Stephen Early <steve@greenend.org.uk>,
Richard Kettlewell <rjk@terraraq.org.uk>
Build-Depends: debhelper (>= 5), libgmp3-dev, libadns1-dev, bison, flex,
- libbsd-dev, python-ipaddr, python-future, tclx, tcl, libtcl-chiark-1
+ libbsd-dev, python-ipaddress, python-future, tclx, tcl, libtcl-chiark-1
Standards-Version: 3.0.1
Package: secnet
# You may redistribute this fileand/or modify it under the terms of
# the GNU General Public License as published by the Free Software
# Foundation; either version 2, or (at your option) any later version.
-# Note however that this version of ipaddrset.py uses the Python
-# ipaddr library from Google, which is licenced only under the Apache
-# Licence, version 2.0, which is only compatible with the GNU GPL v3
-# (or perhaps later versions), and not with the GNU GPL v2.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
from __future__ import print_function
from __future__ import unicode_literals
-import ipaddr
-from ipaddr import IPNetwork, IPAddress
+import ipaddress
+from ipaddress import ip_network, ip_address
import ipaddrset
from ipaddrset import IPAddressSet
-v4a=IPAddress('172.18.45.6')
+v4a=ip_address('172.18.45.6')
s=IPAddressSet()
print('s =', s)
-s.append([IPNetwork('172.18.45.0/24')])
-s.append([IPNetwork('2001:23:24::/48')])
+s.append([ip_network('172.18.45.0/24')])
+s.append([ip_network('2001:23:24::/48')])
print(s)
-t=IPAddressSet(map(IPNetwork,['172.31.80.8/32','172.18.45.192/28']))
+t=IPAddressSet(map(ip_network,['172.31.80.8/32','172.18.45.192/28']))
print('t =', t)
print(t <= s)
print(t == s)
for n1s in ['172.18.44.0/23','172.18.45.6/32','172.18.45.0/24']:
- n1=IPNetwork(n1s)
+ n1=ip_network(n1s)
print(n1)
print(s.contains(n1))
print(t.contains(n1))
-"""IP address set manipulation, built on top of ipaddr.py"""
+"""IP address set manipulation, built on top of ipaddress.py"""
# This file is Free Software. It was originally written for secnet.
#
# along with this software; if not, see
# https://www.gnu.org/licenses/gpl.html.
-import ipaddr
+import ipaddress
_vsns = [6,4]
# constructors
def __init__(self,l=[]):
- "New set contains each ipaddr.IPNetwork in the sequence l"
+ "New set contains each IP*Network in the sequence l"
self._v = {}
for v in _vsns:
self._v[v] = [ ]
# housekeeping and representation
def _compact(self):
for v in _vsns:
- self._v[v] = ipaddr.collapse_address_list(self._v[v])
+ self._v[v] = list(
+ ipaddress.collapse_addresses(self._v[v]))
def __repr__(self):
return "IPAddressSet(%s)" % self.networks()
def str(self,comma=",",none="-"):
# mutators
def append(self,l):
- "Appends each ipaddr.IPNetwork in the sequence l to self"
+ "Appends each IP*Network in the sequence l to self"
self._append(l)
self._compact()
def _append(self,l):
- "Appends each ipaddr.IPNetwork in the sequence l to self"
+ "Appends each IP*Network in the sequence l to self"
for a in l:
self._v[a.version].append(a)
except KeyError:
v = None
if v:
- return self._contains_net(ipaddr.IPNetwork(thing))
+ return self._contains_net(ipaddress.ip_network(thing))
else:
return self.__ge__(thing)
"Returns a set containing all addresses"
s=IPAddressSet()
for v in _vsns:
- a=ipaddr.IPAddress(0,v)
- n=ipaddr.IPNetwork("%s/0" % a)
+ if v==6: a=ipaddress.IPv6Address(0)
+ elif v==4: a=ipaddress.IPv4Address(0)
+ else: raise "internal error"
+ n=ipaddress.ip_network("%s/0" % a)
s.append([n])
return s
cd ~/secnet/sites-test/
execute ~/secnet/make-secnet-sites.py -u vpnheader groupfiles sites
-This program is part of secnet. It relies on the "ipaddr" library from
-Cendio Systems AB.
+This program is part of secnet.
"""
import getopt
import re
-import ipaddr
+import ipaddress
# entry 0 is "near the executable", or maybe from PYTHONPATH=.,
# which we don't want to preempt
class single_ipaddr (basetype):
"An IP address"
def __init__(self,w):
- self.addr=ipaddr.IPAddress(w[1])
+ self.addr=ipaddress.ip_address(w[1])
def __str__(self):
return '"%s"'%self.addr
def __init__(self,w):
self.set=ipaddrset.IPAddressSet()
for i in w[1:]:
- x=ipaddr.IPNetwork(i,strict=True)
+ x=ipaddress.ip_network(i,strict=True)
self.set.append([x])
def __str__(self):
return ",".join(map((lambda n: '"%s"'%n), self.set.networks()))