42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|||
|
|
"""Runs a domain WHOIS lookup and prints a JSON-serializable summary to stdout.
|
||
|
|
|
||
|
|
Used by App\\Osint\\Runners\\WhoisRunner. Takes exactly one argument: the domain.
|
||
|
|
"""
|
||
|
|
import datetime
|
||
|
|
import json
|
||
|
|
import sys
|
||
|
|
|
||
|
|
import whois
|
||
|
|
|
||
|
|
|
||
|
|
def to_jsonable(value):
|
||
|
|
if isinstance(value, (list, tuple)):
|
||
|
|
return [to_jsonable(v) for v in value]
|
||
|
|
if isinstance(value, (datetime.datetime, datetime.date)):
|
||
|
|
return value.isoformat()
|
||
|
|
if isinstance(value, (str, int, float, bool)) or value is None:
|
||
|
|
return value
|
||
|
|
return str(value)
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
if len(sys.argv) != 2:
|
||
|
|
print(json.dumps({"error": "usage: whois_lookup.py <domain>"}), file=sys.stderr)
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
domain = sys.argv[1]
|
||
|
|
|
||
|
|
try:
|
||
|
|
record = whois.whois(domain)
|
||
|
|
except Exception as exc:
|
||
|
|
print(json.dumps({"error": str(exc)}), file=sys.stderr)
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
data = {key: to_jsonable(value) for key, value in dict(record).items()}
|
||
|
|
print(json.dumps(data))
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|