Skip to main content

Pretty-print IPy's IPSets

Project description

Pretty-print IPy’s IPSets in a human-readable fashion.

https://coveralls.io/repos/djmitche/prettyip/badge.svg?branch=master https://travis-ci.org/djmitche/prettyip.svg?branch=master

Compatibility

Everywhere IPy runs, so does this – CPython-2.6 through 3.4.

Usage

Explicitly:

from IPy import IPSet, IP
import prettyip

my_ipset = IPSet([IP('10.0.0.0/8')]) - IPSet([IP('10.0.1.2')])
print prettyip.pretty_ipset(my_ipset)

Or, monkey-patch IPy:

import prettyip

prettyip.patch_ipy()

my_ipset = IPSet([IP('10.0.0.0/8')]) - IPSet([IP('10.0.1.2')])
print my_ipset

Results

Simple IPs:

 >>> prettyip.pretty_ipset(IPSet([IP('10.0.0.0/8')]))
'10.0.0.0/8'

Ranges:

>>> IPSet([IP('10.120.13.11'), IP('10.120.13.12/30'), IP('10.120.13.16')])
IPSet([IP('10.120.13.11'), IP('10.120.13.12/30'), IP('10.120.13.16')])
>>> prettyip.pretty_ipset(_)
'10.120.13.1{1-6}'

Big netblocks with smaller pieces missing:

 >>> IPSet([IP('1.0.0.0/8')]) - IPSet([IP('1.0.1.0/24')]) - IPSet([IP('1.0.9.0/24')])
 IPSet([IP('1.0.0.0/24'), IP('1.0.2.0/23'), IP('1.0.4.0/22'),
    IP('1.0.8.0/24'), IP('1.0.10.0/23'), IP('1.0.12.0/22'), IP('1.0.16.0/20'),
    IP('1.0.32.0/19'), IP('1.0.64.0/18'), IP('1.0.128.0/17'),
    IP('1.1.0.0/16'), IP('1.2.0.0/15'), IP('1.4.0.0/14'), IP('1.8.0.0/13'),
    IP('1.16.0.0/12'), IP('1.32.0.0/11'), IP('1.64.0.0/10'),
    IP('1.128.0.0/9')])
 >>> prettyip.pretty_ipset(_)
'1.0.0.0/8 except 1.0.1.0/24, 1.0.9.0/24'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prettyip-1.1.3.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

prettyip-1.1.3-py2.py3-none-any.whl (6.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file prettyip-1.1.3.tar.gz.

File metadata

  • Download URL: prettyip-1.1.3.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for prettyip-1.1.3.tar.gz
Algorithm Hash digest
SHA256 8afd6f324ee7369cd7e210241531506e5adbcbce4a861aa39483eb0d00a1f21b
MD5 1b91fea6d473220b14514a07ce81ae4c
BLAKE2b-256 a12368f590830749361d6a1467f27fbd7a9aaa5c7585695f7f6b4f3d3e2ddc76

See more details on using hashes here.

File details

Details for the file prettyip-1.1.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for prettyip-1.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 253bd526040384ddf72a043b7bab45e6ec5009ed0735a0bb3f1ea6b043b5aed4
MD5 f3abc436167e70944a428f8f95242d22
BLAKE2b-256 48ec7a0f819b80e589eb21a14f86f862095589c1dbcf512856dfebbf88b4a6da

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page