diff options
author | Franck Cuny <franck@fcuny.net> | 2024-05-05 09:59:11 -0700 |
---|---|---|
committer | Franck Cuny <franck@fcuny.net> | 2024-05-05 09:59:11 -0700 |
commit | c54422174f2af26d0b204cc155ef9e366baa8a33 (patch) | |
tree | a2d09ace5a8b7a72b60c5ff195f2f0b2656d858c /src | |
parent | some cleanup for CI (diff) | |
download | world-c54422174f2af26d0b204cc155ef9e366baa8a33.tar.gz |
move ipconverter under `src`
Diffstat (limited to 'src')
-rwxr-xr-x | src/cli/ipconverter.py | 25 | ||||
-rwxr-xr-x | src/cli/seqstat.py | 2 |
2 files changed, 26 insertions, 1 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}") diff --git a/src/cli/seqstat.py b/src/cli/seqstat.py index a9d5e64..196fe56 100755 --- a/src/cli/seqstat.py +++ b/src/cli/seqstat.py @@ -17,7 +17,7 @@ def histogram(sequence): @click.command() -@click.argument('numbers', nargs=-1, type=float) +@click.argument("numbers", nargs=-1, type=float) def cli(numbers): h = histogram(numbers) print("".join(h)) |