-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
26 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
from __future__ import print_function | ||
|
||
__author__ = 'Jathan McCollum' | ||
__email__ = '[email protected]' | ||
__version__ = '0.6.5' | ||
__version__ = '0.7.0' | ||
|
||
""" | ||
Intelligently parse IPv4/IPv6 addresses, CIDRs, ranges, and wildcard matches to | ||
|
@@ -14,15 +15,18 @@ | |
interactively for debugging purposes. | ||
""" | ||
|
||
# stdlib | ||
import itertools | ||
import logging | ||
from netaddr import (AddrFormatError, IPAddress, IPGlob, IPNetwork, IPRange, | ||
IPSet, spanning_cidr) | ||
import os | ||
import re | ||
import socket | ||
import sys | ||
|
||
# pypi | ||
from netaddr import (AddrFormatError, IPAddress, IPGlob, IPNetwork, IPRange, | ||
IPSet, spanning_cidr) | ||
|
||
# Globals | ||
EVERYTHING = ['internet at large', '*', 'all', 'any', 'internet', '0.0.0.0', | ||
'0.0.0.0/0', '0.0.0.0-255.255.255.255'] | ||
|
@@ -377,15 +381,15 @@ def optimize_network_range(ipstr, threshold=0.9, verbose=DEBUG): | |
ratio = float(len(strict)) / float(len(loose)) | ||
|
||
if verbose: | ||
print 'Subnet usage ratio: %s; Threshold: %s' % (ratio, threshold) | ||
print('Subnet usage ratio: %s; Threshold: %s' % (ratio, threshold)) | ||
|
||
if ratio >= threshold: | ||
if verbose: | ||
print 'Over threshold, IP Parse Mode: LOOSE' | ||
print('Over threshold, IP Parse Mode: LOOSE') | ||
result = loose.iter_cidrs() | ||
else: | ||
if verbose: | ||
print 'Under threshold, IP Parse Mode: STRICT' | ||
print('Under threshold, IP Parse Mode: STRICT') | ||
result = strict.iter_cidrs() | ||
|
||
return result | ||
|
@@ -464,7 +468,7 @@ def dump(cidr): | |
log.debug('dump(): Got? %r' % cidr) | ||
|
||
ip_first = IPAddress(cidr.first) | ||
ip_firsthost = ip_first if single else cidr.iter_hosts().next() | ||
ip_firsthost = ip_first if single else next(cidr.iter_hosts()) | ||
ip_gateway = IPAddress(cidr.last - 1) | ||
ip_bcast = cidr.broadcast | ||
ip_netmask = cidr.netmask | ||
|
@@ -529,7 +533,7 @@ def parse_args(argv): | |
def phelp(): | ||
"""I help.""" | ||
parser.print_help() | ||
print notes | ||
print(notes) | ||
|
||
if opts.help or len(args) == 1: | ||
phelp() | ||
|
@@ -558,9 +562,9 @@ def main(): | |
cidr = cidrize(ipstr, modular=False) | ||
if cidr: | ||
if opts.verbose: | ||
print dump(cidr), | ||
print(dump(cidr),) | ||
else: | ||
print output_str(cidr) | ||
print(output_str(cidr)) | ||
except IndexError: | ||
return -1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
from __future__ import print_function | ||
|
||
try: | ||
from setuptools import setup, Command | ||
|
@@ -10,10 +11,10 @@ | |
import unittest | ||
|
||
#from cidrize import __version__ | ||
__version__ = '0.6.4' | ||
__version__ = '0.7.0' | ||
|
||
if sys.version_info[:2] < (2, 4): | ||
print "This package requires Python 2.4+. Sorry!" | ||
if sys.version_info[:2] < (2, 6): | ||
print("This package requires Python 2.6+. Sorry!") | ||
sys.exit(-1) | ||
|
||
class CleanCommand(Command): | ||
|
@@ -25,7 +26,7 @@ def finalize_options(self): | |
self.files = './build ./dist ./MANIFEST ./*.pyc ./*.egg-info' | ||
def run(self): | ||
#files = './build ./dist ./MANIFEST ./*.pyc' | ||
print 'Cleaning: %s' % self.files | ||
print('Cleaning: %s' % self.files) | ||
os.system('rm -rf ' + self.files) | ||
|
||
class TestCommand(Command): | ||
|
@@ -54,7 +55,8 @@ def run(self): | |
author_email = '[email protected]', | ||
py_modules = ['cidrize'], | ||
scripts = ['scripts/cidr'], | ||
install_requires=['netaddr>=0.7.6'], | ||
install_requires=['netaddr>=0.7.6',], | ||
tests_require=['netaddr>=0.7.6', ], | ||
keywords = [ | ||
'Networking', 'Systems Administration', 'IANA', 'IEEE', 'CIDR', 'IP', | ||
'IPv4', 'IPv6', 'IP Address', 'Firewalls', 'Security', | ||
|
@@ -73,9 +75,9 @@ def run(self): | |
'License :: OSI Approved :: BSD License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 2.5', | ||
'Programming Language :: Python :: 2.6', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Topic :: Education :: Testing', | ||
'Topic :: Internet', | ||
'Topic :: Internet :: Name Service (DNS)', | ||
|