Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cisco IMC(CIMC)へのログイン・ログアウトするスクリプト
#!/usr/bin/env python3
import xmltodict
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def login(url="", user="", password=""):
"""
:rtype: str
:return: cookie
"""
# Create Header.
headers = { 'content-type': 'application/x-www-form-urlencoded' }
# Create Request Body.
request_body = {}
request_body['aaaLogin'] = {}
request_body['aaaLogin']['@inName'] = user
request_body['aaaLogin']['@inPassword'] = password
# Login
r = requests.post(url, headers=headers, data=xmltodict.unparse(request_body), verify=False)
# return Cookie
return xmltodict.parse(r.text)['aaaLogin']['@outCookie']
def logout(url="", cookie=""):
"""
:rtype: str
:return: logout result
"""
# Create Header.
headers = { 'content-type': 'application/x-www-form-urlencoded' }
# Create Request Body.
request_body = {}
request_body['aaaLogout'] = {}
request_body['aaaLogout']['@cookie'] = cookie
request_body['aaaLogout']['@inCookie'] = cookie
# Logout
r = requests.post(url, headers=headers, data=xmltodict.unparse(request_body), verify=False)
# <aaaLogout cookie="cookie" response="yes" outStatus="success"> </aaaLogout>
if(r.status_code == 200):
return xmltodict.parse(r.text)['aaaLogout']['@outStatus']
if __name__ == "__main__":
url="https://192.168.1.56/nuova"
user="admin"
password="password"
# Get Cookie.
r = login(url=url, user=user, password=password)
print("cookie: %s" % r)
# logout
r = logout(url=url, cookie=r)
print("Logout: %s" % r)
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.