24 lines
723 B
Python
Executable File
24 lines
723 B
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import socket, httplib, httplib2
|
|
import sys
|
|
|
|
URL = "http://"+sys.argv[1]+"/cgi-bin/reboot.cgi"
|
|
USER = sys.argv[2]
|
|
PASS = sys.argv[3]
|
|
|
|
h = httplib2.Http(cache=None, timeout=0.2)
|
|
h.add_credentials(USER, PASS)
|
|
|
|
|
|
try:
|
|
response, content = h.request(URL, "GET", headers={'cache-control':'no-cache'})
|
|
if response.status==401:
|
|
print "Unauthorized, Wrong PASSWORD"
|
|
elif response.status==404:
|
|
URL = "http://"+sys.argv[1]+"/api/reboot"
|
|
response, content = h.request(URL, "GET", headers={'cache-control':'no-cache'})
|
|
except httplib2.ServerNotFoundError:
|
|
print "HOST is Down"
|
|
except (socket.timeout, socket.error, httplib2.HttpLib2Error, httplib.ResponseNotReady):
|
|
print "ERROR" |