frankenrouter/updateipcache.py

38 lines
979 B
Python
Raw Normal View History

# downloads and update the ip cache.
import requests
import json
import sys
2018-02-23 07:17:21 -05:00
import re
2018-02-23 07:17:21 -05:00
conffile = open('/root/frankenrouter/config.sh', 'r')
for line in conffile:
if re.search('LABEL', line):
slave_name = line.split('=', 1)[1].rstrip().replace('"', '')
conffile.close()
2018-02-23 07:17:21 -05:00
conffile = open('/root/frankenrouter/config.sh', 'r')
for line in conffile:
if re.search('APIHOST', line):
api_host = line.split('=', 1)[1].rstrip().replace('"', '')
conffile.close()
api_url = 'https://' + str(api_host) + '/vmanager/slavetables'
###
try:
data = {"passphrase": "batkataisthebest1", "slavename": str(slave_name)}
apireq = requests.post(api_url, headers={'Content-Type': 'application/json'}, data=json.dumps(data), timeout=30)
result = apireq.json()
except:
sys.exit()
if result['status'] == 'ok':
del result['status']
wr = open('/root/pubip.cache', 'w')
wr.write(json.dumps(result))
wr.close()
print('public ip cache updated')