33 lines
963 B
Python
33 lines
963 B
Python
import urllib2
|
|
import json
|
|
import commands
|
|
import time
|
|
url = "https://api.github.com/repositories"
|
|
send_headers = {"Content-Type":"application/json"}
|
|
|
|
def get_ip_address(ifname):
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
return socket.inet_ntoa(fcntl.ioctl(
|
|
s.fileno(),
|
|
0x8915, # SIOCGIFADDR
|
|
struct.pack('256s', ifname[:15])
|
|
)[20:24])
|
|
|
|
while True:
|
|
req = urllib2.Request(url,headers = send_headers)
|
|
try :
|
|
result = urllib2.urlopen(req)
|
|
ratelimit_remaining = result.info().get("X-RateLimit-Remaining")
|
|
print "ratelimit_remaining: %s"%ratelimit_remaining
|
|
if ratelimit_remaining == 0:
|
|
print get_ip_address("eth0")
|
|
commands.getoutput("pppoe-stop")
|
|
time.sleep(1)
|
|
commands.getoutput("pppoe-start")
|
|
print get_ip_address("eth0")
|
|
next_url = result.info().get("Link")
|
|
print next_url.index(">")
|
|
url = next_url[1,next_url.index(">")]
|
|
except Exception, e:
|
|
print e
|