blob: 4e6906b74ba4cf20282cccb8c16a7033ab1843f7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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}")
|