Created
October 22, 2017 10:47
-
-
Save jen6/cc9dc85783040840667f70e971fc6186 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
#import urllib | |
from urllib.parse import urlencode | |
from urllib.request import Request, urlopen | |
from urllib.error import URLError, HTTPError | |
import time | |
import json | |
kHerokuUrl = "http://lit-castle-67838.herokuapp.com" | |
delayTime = 5 | |
#check connection | |
while True: | |
try: | |
req = urlopen(kHerokuUrl, timeout=10) | |
break | |
except (HTTPError, URLError) as e: | |
print("wtf") | |
time.sleep(delayTime) | |
#get ifconfig | |
proc = subprocess.Popen(["ifconfig"], stdout=subprocess.PIPE, shell=True) | |
(out, err) = proc.communicate() | |
local_time = time.asctime( time.localtime(time.time()) ) + '\n' | |
buf = out+bytes(local_time, 'utf-8') | |
#send output of ifconfig + localtime | |
data = {'data':buf} | |
sdata = bytes( urlencode(data).encode()) | |
req = Request(kHerokuUrl + "/user/jen6", data=sdata) | |
resp = urlopen(req) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment