blob: 662ab2f0be48830c0c7aae58b6a935765dd3bab6 (
plain)
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
36
37
38
39
40
41
42
43
44
45
46
|
#!/usr/bin/python3
import urllib.request
import json
import sys
DEMO_ISPS = ('Riseup Networks',)
url = 'https://wtfismyip.com/json'
with urllib.request.urlopen(url) as _url:
data = json.loads(_url.read().decode())
isp = data['YourFuckingISP']
ip = data['YourFuckingIPAddress']
print('ISP >> %s' % isp)
print('IP >> %s' % ip)
class BadCmd(Exception):
pass
try:
cmd = sys.argv[1]
if cmd == 'vpn_on':
assert isp in DEMO_ISPS
elif cmd == 'vpn_off':
assert isp not in DEMO_ISPS
else:
raise BadCmd()
except BadCmd:
print("Cannot parse that command. Valid commands: vpn_on, vpn_off")
sys.exit(1)
except Exception as exc:
print("IP *NOT* as expected")
print("%r" % exc)
sys.exit(1)
else:
print("OK :)")
sys.exit(0)
|