Skip to content

Instantly share code, notes, and snippets.

@lewoudar
Created December 1, 2020 07:02
Show Gist options
  • Save lewoudar/7194eb51ba052cfa1f5973d507207deb to your computer and use it in GitHub Desktop.
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
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