summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Shields <mshields@google.com>2015-08-17 17:23:36 -0700
committerMichael Shields <mshields@google.com>2015-08-17 17:23:36 -0700
commit8086aac1e608cb9f77c9050e3e3bf9d77abd5dbe (patch)
treefcb146174dac185f53fc0ba2f134c753dc4abf36
parent0f62dd7f7f148a6d3bf1a4abbea1dc8c106189ec (diff)
downloadipaddr-py-8086aac1e608cb9f77c9050e3e3bf9d77abd5dbe.tar.gz
Remove obsolete documentation on 1.x and 3.x ("3144").
Documentation on the new module is now at: https://docs.python.org/3/library/ipaddress.html
-rw-r--r--wiki/ExampleUsage-1x.wiki124
-rw-r--r--wiki/Using3144.wiki261
2 files changed, 0 insertions, 385 deletions
diff --git a/wiki/ExampleUsage-1x.wiki b/wiki/ExampleUsage-1x.wiki
deleted file mode 100644
index 3a978ac..0000000
--- a/wiki/ExampleUsage-1x.wiki
+++ /dev/null
@@ -1,124 +0,0 @@
-
-Examples of the functionality of the 1.x version of the ipaddr library. Documentation for the current version (2.x) will be coming shortly.
-
-A lot of the functionality of the IPv4 class is derived from the BaseIP class. The same is true for the IPv6 class. that means that all of the functionality you see here is exactly the same when dealing with IPv6 addresses.
-
-=== IPv4 ===
-_using ipaddr with IPv4 addresses_
-
-Start by creating your address object.
-You can create an IPv4 object with:
-
-netmask
-{{{
->>> addr = ipaddr.IPv4('1.1.1.1/255.255.255.0')
->>> addr
-IPv4('1.1.1.1/24')
-}}}
-
-hostmask
-{{{
->>> addr = ipaddr.IPv4('1.1.1.1/0.0.0.255')
->>> addr
-IPv4('1.1.1.1/24')
-}}}
-
-prefix length
-{{{
->>> addr = ipaddr.IPv4('1.1.1.1/24')
->>> addr
-IPv4('1.1.1.1/24')
-}}}
-
-nothing (nothing implies a /32 netmask)
-{{{
->>> addr = ipaddr.IPv4('1.1.1.1')
->>> addr
-IPv4('1.1.1.1/32')
-}}}
-
-Many of the standard Python operations are supported
-{{{
-# comparisons
->>> ipaddr.IPv4('1.1.1.1') == ipaddr.IPv4('1.1.1.2')
-False
->>> ipaddr.IPv4('1.1.1.1') < ipaddr.IPv4('1.1.1.2')
-True
-
-# list inclusion
->>> a = ipaddr.IPv4('1.1.1.1')
->>> b = ipaddr.IPv4('1.1.1.2')
->>> c = ipaddr.IPv4('1.1.1.3')
->>> a in [a, b, c]
-True
-
-# inclusion
->>> ipaddr.IPv4('1.1.1.1') in ipaddr.IPv4("1.0.0.0/8")
-True
-
-# sorting
->>> a = ipaddr.IPv4('1.1.1.10')
->>> b = ipaddr.IPv4('1.10.1.10')
->>> c = ipaddr.IPv4('1.1.10.10')
->>> d = ipaddr.IPv4('1.1.1.1')
->>> sorted([a, b, c, d])
-[IPv4('1.1.1.1/32'), IPv4('1.1.1.10/32'), IPv4('1.1.10.10/32'), IPv4('1.10.1.10/32')]
-
-# str
->>> str(ipaddr.IP('1.2.3.4'))
-'1.2.3.4/32'
-
-# int/hex.
->>> int(ipaddr.IP('1.2.3.4'))
-16909060
->>> hex(ipaddr.IP('1.2.3.4'))
-'0x1020304'
-}}}
-
-Additionally, there are quite a few network-specific features available to ipaddr.
-{{{
->>> ipaddr.IPv4('10.0.0.0/8').Supernet()
-IPv4('10.0.0.0/7')
-
->>> ipaddr.IPv4('10.0.0.0/8').Subnet()
-[IPv4('10.0.0.0/9'), IPv4('10.128.0.0/9')]
-
->>> ipaddr.IPv4('10.0.0.0/8').Subnet(prefixlen_diff=2) # this returns networks with a prefix length of /10
-[IPv4('10.0.0.0/10'), IPv4('10.64.0.0/10'),
- IPv4('10.128.0.0/10'), IPv4('10.192.0.0/10')]
-
-# AddressExclude removes an address from a superblock.
->>> ipaddr.IPv4('10.0.0.0/24').AddressExclude(ipaddr.IPv4('10.0.0.0/32'))
-[IPv4('10.0.0.1/32'), IPv4('10.0.0.2/31'),
- IPv4('10.0.0.4/30'), IPv4('10.0.0.8/29'),
- IPv4('10.0.0.16/28'), IPv4('10.0.0.32/27'),
- IPv4('10.0.0.64/26'), IPv4('10.0.0.128/25')]
-
-}}}
-
-=== IPv6 ===
-
-IPv6 methods are exactly the same as their IPv4 counterparts. this is because a lot of the functionality for both the IPv4 and IPv6 classes is inherited from the BaseIP class. For example:
-
-{{{
->>> addr = ipaddr.IPv6('ffff::1/120')
->>> addr
-IPv6('ffff::1/120')
->>> addr.prefixlen
-120
->>> addr == ipaddr.IPv6('ffff::2/120')
-False
->>> addr > ipaddr.IPv6('ffff::2/120')
-False
->>> addr < ipaddr.IPv6('ffff::2/120')
-True
->>> addr in ipaddr.IPv6('ffff::1/119')
-True
->>> hex(addr)
-'0xFFFF0000000000000000000000000001L'
->>> int(addr)
-340277174624079928635746076935438991361L
-}}}
-
-
-As always, consult your local help(ipaddr) pydoc documentation with questions. \ No newline at end of file
diff --git a/wiki/Using3144.wiki b/wiki/Using3144.wiki
deleted file mode 100644
index f3cb793..0000000
--- a/wiki/Using3144.wiki
+++ /dev/null
@@ -1,261 +0,0 @@
-# Information and examples on using ipaddr from branches/3144
-
-= Using ipaddr =
-
-What follows is an introducion to using ipaddr-py. These exmples use the version from branches/3144.
-
-== Creating Address/Network/Interface objects ==
-
- Since ipaddr-py is library for inspecting and manipulating IP address, the first thing you'll want to do is create some objects. You can use ipaddr to create objects from strings, integers or other ipaddr objects.
-
- * Creating Addresses.
-
- Addresses are the most basic unit. They are indivisable.
-
- IPv4 Address:
-
- {{{
- # string constructor.
- >>> ipaddr.IPv4Address('192.0.2.1')
- IPv4Address('192.0.2.1')
-
- # integer constructor.
- >>> ipaddr.IPv4Address(3221225985)
- IPv4Address('192.0.2.1')
-
- # copy constructor.
- >>> addr = ipaddr.IPv4Address('192.0.2.1')
- >>> ipaddr.IPv4Address(addr)
- IPv4Address('192.0.2.1')
- }}}
-
- IPv6 Address:
-
- {{{
- # string constructor.
- >>> ipaddr.IPv6Address('2001:DB8::1')
- IPv6Address('2001:db8::1')
-
- # integer constructor - this one's a mouthful.
- >>> ipaddr.IPv6Address(42540766411282592856903984951653826561L)
- IPv6Address('2001:db8::1')
-
- # copy constructor
- >>> ipaddr.IPv6Address(addr)
- IPv6Address('2001:db8::1')
- }}}
-
- * Creating Networks.
-
- Addresses are usually grouped together in Networks, so ipaddr provides a way to create, inspect and maniuplate those as well. The constructors look identical to their corresponding address constructor.
-
- IPv4 Network:
- {{{
- >>> ipaddr.IPv4Network('192.0.2.0/24')
- IPv4Network('192.0.2.0/24')
- >>> ipaddr.IPv4Network(3221225984)
- IPv4Network('192.0.2.0/32')
- >>> addr = ipaddr.IPv4Network('192.0.2.0/24')
- >>> ipaddr.IPv4Network(addr)
- IPv4Network('192.0.2.0/24')
- }}}
-
- IPv6 Network:
- {{{
- >>> ipaddr.IPv6Network('2001:db8::0/96')
- IPv6Network('2001:db8::/96')
- >>> ipaddr.IPv6Network(42540766411282592856903984951653826560L)
- IPv6Network('2001:db8::/128')
- >>> addr = ipaddr.IPv6Network('2001:db8::0/96')
- >>> ipaddr.IPv6Network(addr)
- IPv6Network('2001:db8::/96')
- }}}
-
- Network objects cannot have any host bits set. The practical effect of this is that, '192.0.2.1/24' does not describe a network. It's referred to as an interface object since the ip-on-a-network notation is commonly used to describe network interfaces of a computer on a given network.
-
-Note: when creating a network object from an integer, the prefix length
-(netmask) is assumed to be all ones. So IPv4 networks will have a /32 netmask
-and IPv6 networks will have a /128 netmask.
-
- * Creating hybrid objects.
-
- As mentioned just above, if you need to describe an address on a particular network, neither the address nor the network classes is appropriate. Since the notation 192.0.2.1/24 is so common among network engineers and the people who write tools for firewalls and routers, ipaddr provides a set of hybrid classes. By now, the constructor syntax should look familair.
-
- IPv4Interface:
- {{{
- >>> ipaddr.IPv4Interface('192.0.2.1/24')
- IPv4Interface('192.0.2.1/24')
- >>> ipaddr.IPv4Interface(3221225985)
- IPv4Interface('192.0.2.1/32')
- >>> addr = ipaddr.IPv4Interface('192.0.2.1/24')
- >>> ipaddr.IPv4Interface(addr)
- IPv4Interface('192.0.2.1/24')
- }}}
-
- IPv6Interface:
- {{{
- >>> ipaddr.IPv6Interface('2001:db8::1/96')
- IPv6Interface('2001:db8::1/96')
- >>> ipaddr.IPv6Interface(42540766411282592856903984951653826561L)
- IPv6Interface('2001:db8::1/128')
- >>> addr = ipaddr.IPv6Interface('2001:db8::1/96')
- >>> ipaddr.IPv6Interface(addr)
- IPv6Interface('2001:db8::1/96')
- }}}
-
-Note: Just like with the network objects, when you create an interface object with an integer, the netmask is assumed to be all ones.
-
- Finally, if you don't know at the time coding what type of addresses you might be handling, or you don't really care and you'd like the same code to handle both, ipaddr provides generic factory functions which look at the address and try to return an object of the correct for you.
-
- * Addresses
- {{{
- >>> ipaddr.ip_address('192.0.2.1')
- IPv4Address('192.0.2.1')
- >>> ipaddr.ip_address('2001:db8::1')
- IPv6Address('2001:db8::1')
- >>> ipaddr.ip_address(1)
- IPv4Address('0.0.0.1')
- >>> addr = ipaddr.ip_address('2001:db8::1')
- >>> ipaddr.ip_address(addr)
- IPv6Address('2001:db8::1')
- }}}
-
- * Networks
- {{{
- >>> ipaddr.ip_network('192.0.2.0/24')
- IPv4Network('192.0.2.0/24')
- >>> addr = ipaddr.ip_network('192.0.2.0/24')
- >>> ipaddr.ip_network(addr)
- IPv4Network('192.0.2.0/24')
- >>> ipaddr.ip_network('2001:db8::0/96')
- IPv6Network('2001:db8::/96')
- }}}
-
- * Interfaces
- {{{
- >>> ipaddr.ip_interface('192.0.2.1/24')
- IPv4Interface('192.0.2.1/24')
- >>> ipaddr.ip_interface('2001:db8::1/96')
- IPv6Interface('2001:db8::1/96')
- }}}
-
-Note: Since IPv4 addresses are 2^32^ bits and IPv6 addresses are 2^128^ bits, all integers <= 2^32^ - 1 are assumed to be IPv4. If you know that an address is an IPv6 address, you should pass version=6 to ip_address().
-
- * explicit versioning
- {{{
- >>> ipaddr.ip_address(3221225985)
- IPv4Address('192.0.2.1')
- >>> ipaddr.ip_address(3221225985, version=6)
- IPv6Address('::c000:201')
- }}}
-
-== Inspecting Address/Network/Interface Objects ==
-
- You've gone to the trouble of creating an IPv(4|6)(Address|Network|Interface) object, so you probably want to get information about it. ipaddr tries to make doing this easy and intuitive.
-
- * IP version.
- {{{
- >>> addr4 = ipaddr.ip_address('192.0.2.1')
- >>> addr6 = ipaddr.ip_address('2001:db8::1')
- >>> addr6.version
- 6
- >>> addr4.version
- 4
- }}}
-
- * Network/Interface
- {{{
- >>> net4 = ipaddr.ip_network('192.0.2.0/24')
- >>> net6 = ipaddr.ip_network('2001:db8::0/96')
- }}}
-
- * finding out how many individual addresses are in a network.
- {{{
- >>> net4.numhosts
- 256
- >>> net6.numhosts
- 4294967296L
- }}}
-
- * iterating through the 'usable' addresses on a network.
- {{{
- >>> for x in net4.iterhosts():
- print x
- 192.0.2.1
- 192.0.2.2
- 192.0.2.3
- 192.0.2.4
- [snip]
- 192.0.2.252
- 192.0.2.253
- 192.0.2.254
- }}}
-
- * host/netmask
- {{{
- >>> net6.netmask
- IPv6Address('ffff:ffff:ffff:ffff:ffff:ffff::')
- >>> net6.hostmask
- IPv6Address('::ffff:ffff')
- }}}
-
- * Exploding or compressing the address
- {{{
- >>> net6.exploded
- '2001:0000:0000:0000:0000:0000:0000:0000/96'
- >>> addr6.exploded
- '2001:0000:0000:0000:0000:0000:0000:0001'
- }}}
-
-== Networks/Interfaces as lists ==
-
- It's sometimes useful to treat networks (and interfaces) as lists. This allows us to index them like this:
-
- {{{
- >>> net6[1]
- IPv6Address('2001::1')
- >>> net6[-1]
- IPv6Address('2001::ffff:ffff')
- >>> ipaddr.ip_interface('192.0.2.1/24')[-1]
- IPv4Address('192.0.2.255')
- }}}
-
-This also means that network and interface objects lend themselves to using the list membership test syntax {{{ in }}} like this:
-
- {{{
- if address in network:
- # do something
- }}}
-
- Address, Network and Interface objects can be 'in' a network or an interface object.
-
- {{{
- >>> net4 = ipaddr.ip_network('192.0.2.0/25')
- >>> net4 in ipaddr.ip_network('192.0.2.0/24')
- True
- >>> net4 in ipaddr.ip_interface('192.0.2.0/25')
- True
- net4 in ipaddr.ip_interface('192.0.2.0/26')
- }}}
-
-== Comparisons ==
-
- ipaddr provides some simply, hopefully intuitive ways to compare objects, where it makes sense.
-
- {{{
- >>> ipaddr.ip_address('192.0.2.1') < ipaddr.ip_address('192.0.2.2')
- True
- }}}
-
- A TypeError exception is raised if you try to compare objects of different versions or different types.
-
-== Exceptions raised by ipaddr ==
-
- If you try to create an address/network/interface object with an invalid value for either the address or netmask, ipaddr will raise an AddressValueError or NetmaskValueError respectively. Both of these exceptions have ValueError as their parent class, so if you're not concerned with the particular type of error, you can do the following:
-
- {{{
- try:
- ipaddr.ip_address(address)
- except ValueError:
- print 'address/netmask is invalid: %s' % address
- }}} \ No newline at end of file