-
Notifications
You must be signed in to change notification settings - Fork 0
/
minirdapc.py
executable file
·71 lines (63 loc) · 2.46 KB
/
minirdapc.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3.7
#----------------------------------------------------------------------------------
# minirdapc
#
# (c) carlos@xt6.us
#
# Changed: 2019-03-14
#----------------------------------------------------------------------------------
import click
import requests
import shelve
import datetime
import time
import pyjq
import json
import logging
from minirdapc.rdap_client import rdap_client
logging.basicConfig(level=logging.DEBUG)
def print_banner(short=False):
print("")
print("MINI RDAP CLIENT: (c) Carlos Martinez, carlos@xt6.us")
if not short:
print(" Version 0.2.1 2019-07-04")
print("")
print(" Use --help for usage information.")
print("")
else:
print(" ")
## END print_banner
# cli #######################################################################################
@click.command()
@click.option("--query", help="String to query RDAP for.")
@click.option("--type", default=None, help="RDAP query type, one of autnum, ip or entity")
@click.option("--host", default="https://rdap.lacnic.net/rdap", help="RDAP server to query. Optional, defaults to LACNIC")
@click.option("--advquery", default=None, help="Get ORGID of given prefix.")
@click.option("--apikey", default=None, help="Optional: API Key for LACNIC, used to bypass rate limits.")
def cli(query, type, host, advquery, apikey):
rdapc = rdap_client(host, apikey)
if type in ['ip', 'autnum', 'entity']:
print_banner(True)
res = rdapc.rdap_query(type, query)
print( json.dumps(res, indent=3, sort_keys=True) )
elif advquery in ['prefixToOrgid'] :
print_banner(True)
res = rdapc.prefixToOrgid(query)
out = "{prefix},{orgid}".format(prefix=query, orgid=res)
print(out)
elif advquery in ['getAllResources'] :
print_banner(True)
res = rdapc.getAllResources(query)
out = "{entity},{res}".format(entity=query, res=res)
print(out)
else:
print_banner()
print("Wrong combination of query and advquery. Plase use: ")
print("\ttype = ip | autnum | entity")
print(" OR ")
print("\tadvquery = prefixToOrgid")
# print (str(res))
## end cli ##################################################################################
if __name__ == "__main__":
cli()
#--END-----------------------------------------------------------------------------