Add JSON output support to --me flag
The --me flag now respects the --json option. When used together, chkip will return local and public IP addresses as structured JSON. This allows easier integration into scripts or tools that consume JSON, while maintaining human-readable output as the default. Additionally, CGNAT detection is included in the JSON object as a boolean flag.
This commit is contained in:
parent
4868ff54e2
commit
1d01ada2aa
21
chkip.py
21
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
|
||||
|
Loading…
Reference in New Issue
Block a user