|
1 | | -.. python-iptools documentation master file, created by |
2 | | - sphinx-quickstart on Thu May 24 18:28:05 2012. |
3 | | - You can adapt this file completely to your liking, but it should at least |
4 | | - contain the root `toctree` directive. |
| 1 | +############################## |
| 2 | +iptools - IP Address Utilities |
| 3 | +############################## |
| 4 | +The iptools_ package is a collection of utilities for dealing with IP |
| 5 | +addresses. |
5 | 6 |
|
6 | | -iptools's documentation |
7 | | -======================= |
| 7 | +The project was inspired by a desire to be able to use CIDR_ address notation |
| 8 | +to designate ``INTERNAL_IPS`` in a Django_ project's settings file. |
8 | 9 |
|
9 | | -.. automodule:: iptools |
10 | | - :members: |
11 | | - :exclude-members: IpRange, IpRangeList |
12 | 10 |
|
| 11 | +************ |
| 12 | +Installation |
| 13 | +************ |
| 14 | +Install the latest stable version from PyPi using pip_: |
| 15 | + |
| 16 | +.. code-block:: bash |
| 17 | +
|
| 18 | + pip install iptools |
| 19 | +
|
| 20 | +or setuptools_: |
| 21 | + |
| 22 | +.. code-block:: bash |
| 23 | +
|
| 24 | + easy_install iptools |
| 25 | +
|
| 26 | +Install the latest development version: |
| 27 | + |
| 28 | +.. code-block:: bash |
| 29 | +
|
| 30 | + git clone https://github.com/bd808/python-iptools.git |
| 31 | + cd python-iptools |
| 32 | + python setup.py install |
| 33 | +
|
| 34 | +
|
| 35 | +****************************** |
| 36 | +Using with Django INTERNAL_IPS |
| 37 | +****************************** |
| 38 | +An :class:`iptools.IpRangeList` object can be used in a Django_ settings file |
| 39 | +to allow CIDR_ and/or ``(start, end)`` ranges to be used in the |
| 40 | +``INTERNAL_IPS`` list. |
| 41 | + |
| 42 | +There are many internal and add-on components for Django_ that use the |
| 43 | +INTERNAL_IPS_ configuration setting to alter application behavior or make |
| 44 | +debugging easier. When you are developing and testing an application by |
| 45 | +yourself it's easy to add the ip address that your web browser will be coming |
| 46 | +from to this list. When you are developing in a group or testing from many ips |
| 47 | +it can become cumbersome to add more and more ip addresses to the setting |
| 48 | +individually. |
| 49 | + |
| 50 | +The :class:`iptools.IpRangeList` object can help by replacing the standard |
| 51 | +tuple of addresses recommended by the Django docs with an intelligent object |
| 52 | +that responds to the membership test operator in. This object can be |
| 53 | +configured with dotted quad IP addresses like the default ``INTERNAL_IPS`` |
| 54 | +tuple (eg. '127.0.0.1'), CIDR_ block notation (eg. '127/8', '192.168/16') for |
| 55 | +entire network blocks, and/or (start, end) tuples describing an arbitrary |
| 56 | +range of IP addresses. |
| 57 | + |
| 58 | +Django_'s internal checks against the ``INTERNAL_IPS`` tuple take the form |
| 59 | +``if addr in INTERNAL_IPS`` or ``if addr not in INTERNAL_IPS``. This works |
| 60 | +transparently with the :class:`iptools.IpRangeList` object because it |
| 61 | +implements the magic method ``__contains__`` which python calls when the |
| 62 | +``in`` or ``not in`` operators are used. |
| 63 | + |
| 64 | +.. code-block:: python |
| 65 | +
|
| 66 | + import iptools |
| 67 | +
|
| 68 | + INTERNAL_IPS = iptools.IpRangeList( |
| 69 | + '127.0.0.1', # single ip |
| 70 | + '192.168/16', # CIDR network block |
| 71 | + ('10.0.0.1', '10.0.0.19'), # arbitrary inclusive range |
| 72 | + '::1', # single IPv6 address |
| 73 | + 'fe80::/10', # IPv6 CIDR block |
| 74 | + ) |
| 75 | +
|
| 76 | +
|
| 77 | +*** |
| 78 | +API |
| 79 | +*** |
| 80 | + |
| 81 | +iptools |
13 | 82 | ======= |
14 | | -IpRange |
15 | | -======= |
16 | | -.. autoclass:: IpRange |
| 83 | +.. automodule:: iptools |
| 84 | + |
| 85 | +IpRangeList |
| 86 | +----------- |
| 87 | +.. autoclass:: iptools.IpRangeList |
17 | 88 | :members: |
18 | 89 | :special-members: |
| 90 | + :show-inheritance: |
19 | 91 |
|
20 | | -=========== |
21 | | -IpRangeList |
22 | | -=========== |
23 | | -.. autoclass:: IpRangeList |
| 92 | + |
| 93 | +IpRange |
| 94 | +------- |
| 95 | +.. autoclass:: iptools.IpRange |
24 | 96 | :members: |
25 | 97 | :special-members: |
| 98 | + :show-inheritance: |
| 99 | + |
26 | 100 |
|
27 | | -========= |
28 | | -Constants |
29 | | -========= |
30 | | -.. automodule:: iptools.constants |
| 101 | +IPv4 |
| 102 | +==== |
| 103 | +.. automodule:: iptools.ipv4 |
31 | 104 | :members: |
| 105 | + :show-inheritance: |
| 106 | + |
| 107 | + |
| 108 | +IPv6 |
| 109 | +==== |
| 110 | +.. automodule:: iptools.ipv6 |
| 111 | + :members: |
| 112 | + :show-inheritance: |
32 | 113 |
|
33 | | -Indices and tables |
34 | | -================== |
35 | 114 |
|
| 115 | +****************** |
| 116 | +Indices and tables |
| 117 | +****************** |
36 | 118 | * :ref:`genindex` |
37 | 119 | * :ref:`search` |
| 120 | + |
| 121 | +.. _iptools: http://pypi.python.org/pypi/iptools |
| 122 | +.. _Django: http://www.djangoproject.com/ |
| 123 | +.. _pip: http://www.pip-installer.org/en/latest/ |
| 124 | +.. _setuptools: https://pypi.python.org/pypi/setuptools |
| 125 | +.. _CIDR: http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing |
| 126 | +.. _INTERNAL_IPS: http://docs.djangoproject.com/en/dev/ref/settings/#internal-ips |
0 commit comments