-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyip
More file actions
executable file
·35 lines (29 loc) · 767 Bytes
/
myip
File metadata and controls
executable file
·35 lines (29 loc) · 767 Bytes
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
#!/bin/python
#---------------------------------------------
#
# Get my IP address
#
# RICK PFAHL<pfahlr@gmail.com>
# 3 NOV 2024
#
# OPTIONS:
# --ipv6 | -6 : get ipv6 if set
# --json | -j : output json if set
#
#---------------------------------------------
import argparse
import requests
import json
parser = argparse.ArgumentParser()
parser.add_argument('-6', "--ipv6", action=argparse.BooleanOptionalAction)
parser.add_argument('-j', "--json", action=argparse.BooleanOptionalAction)
args = parser.parse_args()
if args.ipv6:
response = requests.get('https://api64.ipify.org?format=json')
else:
response = requests.get('https://api.ipify.org?format=json')
if args.json:
print(response.text)
else:
data = json.loads(response.text)
print(data['ip'])