diff --git a/chkip.py b/chkip.py index b0eb3b0..58e78e3 100644 --- a/chkip.py +++ b/chkip.py @@ -218,15 +218,22 @@ def main(): if args.me: local_v4, public_v4, public_v6 = get_my_ip() - print(f"Your local IPv4: {local_v4}") - print(f"Your public IPv4: {public_v4}") - print(f"Your public IPv6: {public_v6}") + result = { + "local_ipv4": local_v4, + "public_ipv4": public_v4, + "public_ipv6": public_v6 + } if is_cgnat(public_v4): - print("⚠️ Hinweis: Du befindest dich möglicherweise hinter CGNAT (Carrier-Grade NAT)") - return + result["cgnat"] = True - if not args.domain: - parser.print_help() + if args.json: + print(json.dumps(result, indent=2)) + else: + print(f"Your local IPv4: {result['local_ipv4']}") + print(f"Your public IPv4: {result['public_ipv4']}") + print(f"Your public IPv6: {result['public_ipv6']}") + if result.get("cgnat"): + print("⚠️ Hinweis: Du befindest dich möglicherweise hinter CGNAT (Carrier-Grade NAT)") return domain = args.domain