Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Python script to backup a Cisco Expressway
import requests
import json
import re
def main():
URL = "https://10.1.1.1" # UPDATE
USERNAME = "admin"
PASSWORD = "password" # UPDATE
BACKUP_PASSWORD = "password" # UPDATE
sessionid = ""
# Setup Session
s = requests.Session()
# Login
r = s.post(
url=f"{URL}/login",
data={
"submitButton": "Login",
"username": USERNAME,
"password": PASSWORD,
"formbutton": "Login",
},
headers={"Referer": f"{URL}/login"},
verify=False,
)
# Load Backup and restore page
r = s.get(url=f"{URL}/backuprestore", verify=False)
# Get the sessionid value
# Split the response lines
for line in r.text.splitlines():
if re.search(string=line, pattern="sessionid"):
line = line.split("/><")
line = line[0].split("><")
line = re.sub(string=line[1], pattern='"', repl="")
sessionid = line.split("value=")[1]
break
data = f"sessionid={sessionid}&submitbutton=Create+system+backup+file&backup_password={BACKUP_PASSWORD}&backup_password_confirm={BACKUP_PASSWORD}"
headers = {"Content-Type": "application/x-www-form-urlencoded"}
with s.post(
url=f"{URL}/backuprestore",
data=data,
verify=False,
headers=headers,
stream=True,
) as r:
r.raise_for_status()
timestamp = datetime.utcnow().strftime("%Y_%m_%d__%H_%M_%S")
filename = f"expressway_{timestamp}_backup.tar.gz.enc"
with open(filename, "wb") as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.