Skip to content

Instantly share code, notes, and snippets.

@ragingcomputer
Last active May 26, 2020 02:29
Show Gist options
  • Save ragingcomputer/bb4b03b454954ef67add1da56436ac24 to your computer and use it in GitHub Desktop.
Save ragingcomputer/bb4b03b454954ef67add1da56436ac24 to your computer and use it in GitHub Desktop.
Python Requests Reboot Polycom Phones

Use Python & requests to reboot Polycom Phones

Tested on Polycom VVX 310, VVX 410, and Trio 8800 phones Assumes all phones have the same admin password

Usage: Update phones.py with a list strings containing IP address of phones to reboot Assuming you aren't using default admin password on the phones, update "restart_phone(phone, "Polycom:456")"

phones_list = [
"192.168.1.170",
"192.168.1.171",
]
from requests import post, exceptions
from base64 import b64encode
from time import sleep
from phones import phones_list
# global_configs
timeout = 3
sleep_between_phones = 3
def call_restart_phone(ip_addr, admin_pw):
api_endpoint = 'http://{}/form-submit/Reboot'.format(ip_addr)
headers = {}
headers.update({
"Authorization": 'Basic {}='.format(b64encode(admin_pw.encode('utf8')).decode('ascii')),
"Content-Type": 'application/x-www-form-urlencoded',
"Cookie": 'Authorization=Basic {}='.format(b64encode(admin_pw.encode('utf8')).decode('ascii'))
})
response = post(url=api_endpoint, headers=headers, timeout=timeout)
return response
def restart_phone(ip_addr, admin_pw):
try:
result = call_restart_phone(ip_addr, admin_pw)
if result.status_code == 200:
print("Rebooting {}".format(ip_addr))
sleep(sleep_between_phones)
return True
elif result.status_code == 401:
print("Unauthorized {}".format(ip_addr))
return False
else:
print("Unable to Reboot {}".format(ip_addr))
return False
except exceptions.Timeout as err:
print("Unable to Connect (Timeout) {}".format(ip_addr))
return False
except exceptions.ConnectionError as err:
print("Unable to Connect {} {}".format(ip_addr, err))
return False
except Exception as err:
print("FATAL ERROR {}".format(ip_addr, str(err)))
quit()
for phone in phones_list:
restart_phone(phone, "Polycom:456")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment