Created
December 1, 2020 07:02
-
-
Save lewoudar/7194eb51ba052cfa1f5973d507207deb to your computer and use it in GitHub Desktop.
An implementation of a cli returning the ptr name of an ip address
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
import ipaddress | |
import click | |
class IPParamType(click.ParamType): | |
name = 'ip address' | |
def convert(self, value, param, ctx): | |
try: | |
return ipaddress.ip_address(value) | |
except ValueError: | |
self.fail(f'{value} is not a valid ip address', param, ctx) | |
@click.command() | |
@click.argument('ip_address', type=IPParamType()) | |
def cli(ip_address): | |
"""Returns the PTR name of a given IP_ADDRESS""" | |
click.echo(ip_address.reverse_pointer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment