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:
|
if args.me:
|
||||||
local_v4, public_v4, public_v6 = get_my_ip()
|
local_v4, public_v4, public_v6 = get_my_ip()
|
||||||
print(f"Your local IPv4: {local_v4}")
|
result = {
|
||||||
print(f"Your public IPv4: {public_v4}")
|
"local_ipv4": local_v4,
|
||||||
print(f"Your public IPv6: {public_v6}")
|
"public_ipv4": public_v4,
|
||||||
|
"public_ipv6": public_v6
|
||||||
|
}
|
||||||
if is_cgnat(public_v4):
|
if is_cgnat(public_v4):
|
||||||
print("⚠️ Hinweis: Du befindest dich möglicherweise hinter CGNAT (Carrier-Grade NAT)")
|
result["cgnat"] = True
|
||||||
return
|
|
||||||
|
|
||||||
if not args.domain:
|
if args.json:
|
||||||
parser.print_help()
|
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
|
return
|
||||||
|
|
||||||
domain = args.domain
|
domain = args.domain
|
||||||
|
Loading…
Reference in New Issue
Block a user