From cca7528dacf7556684466e21bcaabdcf5285bc07 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Fri, 2 Dec 2022 10:10:00 -0500 Subject: [PATCH 1/3] updates readme with cli usage --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index c5a8f61..d85a9e0 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,31 @@ Example Usage 338288524927261089654168587652869703991 ``` +A convenice script has been added for doing basic command line checks `icalc.py`. + +```bash +$ icalc.py 192.168.0.1/25 + +Network Information +************************************************** +Network: 192.168.0.0 +Broadcast: 192.168.0.127 +Netmask: 255.255.255.128 +Host Start: 192.168.0.1 +Host End: 192.168.0.126 + + +$ icalc.py 2001:db8:0:1000::/64 + +Network Information +************************************************** +Network: 2001:0db8:0000:1000:0000:0000:0000:0000 +Broadcast: 2001:0db8:0000:1000:ffff:ffff:ffff:ffff +Netmask: ffff:ffff:ffff:ffff:0000:0000:0000:0000 +Host Start: 2001:0db8:0000:1000:0000:0000:0000:0001 +Host End: 2001:0db8:0000:1000:ffff:ffff:ffff:fffe +``` + Bugs/Features ============= From 8fa333e7844964c987c50cb78611a6394a41d46b Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Fri, 2 Dec 2022 10:12:49 -0500 Subject: [PATCH 2/3] updates setup.py with usages --- setup.py | 52 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index 3312398..61cffd9 100755 --- a/setup.py +++ b/setup.py @@ -1,11 +1,15 @@ #!/usr/bin/env python from distutils.core import setup +import os -setup(name='ipcalc', - version='1.99.0', - description='IP subnet calculator', - long_description=''' +scripts = [os.path.join("scripts", "icalc.py")] +setup( + name="ipcalc", + version="1.99.1", + description="IP subnet calculator", + scripts=scripts, + long_description=""" About ===== @@ -33,6 +37,32 @@ >>> long(IP('fe80::213:ceff:fee8:c937')) 338288524927261089654168587652869703991L +A convenice script has been added for doing basic command line checks, icalc.py. + +:: + + $ icalc.py 192.168.0.1/25 + + Network Information + ************************************************** + Network: 192.168.0.0 + Broadcast: 192.168.0.127 + Netmask: 255.255.255.128 + Host Start: 192.168.0.1 + Host End: 192.168.0.126 + + + $ icalc.py 2001:db8:0:1000::/64 + + Network Information + ************************************************** + Network: 2001:0db8:0000:1000:0000:0000:0000:0000 + Broadcast: 2001:0db8:0000:1000:ffff:ffff:ffff:ffff + Netmask: ffff:ffff:ffff:ffff:0000:0000:0000:0000 + Host Start: 2001:0db8:0000:1000:0000:0000:0000:0001 + Host End: 2001:0db8:0000:1000:ffff:ffff:ffff:fffe + + Bugs/Features ============= @@ -42,10 +72,10 @@ ============= Documentation is available from http://ipcalc.rtfd.org/ -''', - author='Wijnand Modderman-Lenstra', - author_email='maze@pyth0n.org', - url='https://github.com/tehmaze/ipcalc/', - py_modules=['ipcalc'], - install_requires=['six'], - ) +""", + author="Wijnand Modderman-Lenstra", + author_email="maze@pyth0n.org", + url="https://github.com/tehmaze/ipcalc/", + py_modules=["ipcalc"], + install_requires=["six"], +) From d0709ee9f263d3342a708c025ee1f56b32e844b8 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Fri, 2 Dec 2022 10:17:45 -0500 Subject: [PATCH 3/3] adds script --- scripts/icalc.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 scripts/icalc.py diff --git a/scripts/icalc.py b/scripts/icalc.py new file mode 100644 index 0000000..0c54418 --- /dev/null +++ b/scripts/icalc.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import ipcalc +import argparse + + +def print_info(subnet): + print("") + print(f"Network Information") + print("*" * 50) + print(f"Network:\t\t{subnet.network()}") + print(f"Broadcast:\t\t{subnet.broadcast()}") + print(f"Netmask:\t\t{subnet.netmask()}") + print(f"Host Start:\t\t{subnet.host_first()}") + print(f"Host End:\t\t{subnet.host_last()}") + print(f"") + + +def main(prefix): + try: + subnet = ipcalc.Network(prefix) + + except ValueError as e: + print(e) + + print_info(subnet) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="IP Calculator") + parser.add_argument("prefix", metavar="PREFIX", type=str) + args = parser.parse_args() + + main(args.prefix)