diff options
Diffstat (limited to '')
-rwxr-xr-x | src/cli/ipconverter.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/cli/ipconverter.py b/src/cli/ipconverter.py new file mode 100755 index 0000000..4e6906b --- /dev/null +++ b/src/cli/ipconverter.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +""" +Utility to convert an IPv4 address to an int, or an int to an IPv4 address. +""" + +import ipaddress + +import click + + +@click.command() +@click.argument("ips", nargs=-1, type=int) +def int2ip(ips): + for ip in ips: + convip = ipaddress.ip_address(ip) + print(f"{ip} → {convip}") + + +@click.command() +@click.argument("ips", nargs=-1, type=str) +def ip2int(ips): + for ip in ips: + convip = int(ipaddress.ip_address(ip)) + print(f"{ip} → {convip}") |