-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-public-ip.py
28 lines (20 loc) · 961 Bytes
/
my-public-ip.py
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
#!/usr/bin/env python3
"""Get your public ipv4 and ipv6"""
import requests
import json
IPV4_URL = "https://test-ipv6.com/ip/?callback=_jqjsp&asn=1&testdomain=test-ipv6.com&testname=test_asn4"
IPV6_URL ="https://ipv6.test-ipv6.ams.vr.org/ip/?callback=_jqjsp&testdomain=test-ipv6.com&testname=test_aaaa"
ENCODING = "utf-8"
def run():
"""Main method"""
ipv4_response = requests.get(url=IPV4_URL)
ipv6_response = requests.get(url=IPV6_URL)
if ipv4_response.status_code == 200 and ipv6_response.status_code == 200:
ipv4_data = json.loads("[" + ipv4_response.content.decode(ENCODING)[7:-2] + "]")
ipv6_data = json.loads("[" + ipv6_response.content.decode(ENCODING)[7:-2] + "]")
print("### Your public IP ###")
print("IPv4: " + ipv4_data[0]['ip'])
print("IPv6: " + ipv6_data[0]['ip'])
else:
print("Something went wrong, fetching your public IP. (Response Status Code is not 200 'OK')")
run()