Created
July 28, 2015 06:55
-
-
Save clonemeagain/1b16c20488f2a9b6fc74 to your computer and use it in GitHub Desktop.
LifeSize support said we should write a python mechanize script to shutdown the server via script.. this is an implementation of that! https://community.lifesize.com/thread/2249
This file contains 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 mechanize | |
import cookielib | |
import urllib2 | |
# Configure the server IP, Username & Password (defaults provided) | |
server='10.0.0.1:8181' | |
username='administrator' | |
password='admin123' | |
# Using mechanize: http://wwwsearch.sourceforge.net/mechanize/ | |
br = mechanize.Browser() | |
cj = cookielib.LWPCookieJar() | |
br.set_cookiejar(cj) | |
br.set_handle_equiv(True) | |
br.set_handle_redirect(True) | |
br.set_handle_referer(True) | |
br.set_handle_robots(False) | |
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) | |
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] | |
# You may need a proxy server | |
#br.set_proxies({"http":"proxy_server_ip:3128"}) | |
try: | |
url = 'https://%s/server-admin/operations/shutdown/poweroff' % server | |
print "Shutting down server: %s" % server | |
br.open(url) | |
except urllib2.URLError as e: | |
print "Failed to connect to %s" % server | |
exit | |
# Login using the web-form | |
br.select_form(nr=0) | |
br.form['username']=username | |
br.form['password']=password | |
br.submit() | |
# Push the "shutdown" button on the confirmation page. | |
br.select_form(nr=0) | |
br.submit(name='power-off') | |
print "LifeSize server is shutting down." | |
# Output whatever the page says, should be: "Powering off the server." | |
print br.response().read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment