'get-all-guest-users.py' Source Code
#!/usr/bin/env python
###########################################################################
# #
# This script demonstrates how to get the Guest users through ISE ERS #
# API by executing a Python script. #
# #
# SECURITY WARNING - DO NOT USE THIS SCRIPT IN PRODUCTION! #
# The script allows connections to SSL sites without trusting #
# the server certificates. #
# For production, it is required to add certificate check. #
# #
# Usage: get-all-guest-users.py <ISE host><SponsorUser><SponsorPassword> #
###########################################################################
import http.client
import base64
import ssl
import sys
# host and authentication credentials
host = sys.argv[1] # "10.20.30.40"
user = sys.argv[2] # "sponsor"
password = sys.argv[3] # "Password1"
conn = http.client.HTTPSConnection("{}:9060".format(host), context=ssl.SSLContext(ssl.PROTOCOL_TLSv1_2))
creds = str.encode(':'.join((user, password)))
encodedAuth = bytes.decode(base64.b64encode(creds))
headers = {
'accept': "application/json",
'authorization': " ".join(("Basic",encodedAuth)),
'cache-control': "no-cache",
}
conn.request("GET", "/ers/config/guestuser/", headers=headers)
res = conn.getresponse()
data = res.read()
print("Status: {}".format(res.status))
print("Header:\n{}".format(res.headers))
print("Body:\n{}".format(data.decode("utf-8")))
Execution
python get-all-guest-users.py 10.20.30.40 sponsor Password1
Status: 200 (OK)
Header:
Cache-Control: no-cache, no-store, must-revalidate
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: JSESSIONIDSSO=9CA59D468388B1E7A37718CD338A4CCD; Path=/; Secure; HttpOnly
Set-Cookie: APPSESSIONID=EDE7764ECB02F15531A3457E54BF88BD; Path=/ers; Secure; HttpOnly
Pragma: no-cache
Date: Thu, 01 Dec 2016 17:06:23 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 897
Server:
Body:
{
"SearchResult": {
"total": 3,
"resources": [
{
"id": "a63fafc1-c22c-11e6-ab89-0242fb4b45f0",
"name": "5lz8g5",
"link": {
"rel": "self",
"href": "https://172.23.166.145:9060/ers/config/guestuser/a63fafc1-c22c-11e6-ab89-0242fb4b45f0",
"type": "application/xml"
}
},
{
"id": "a6392010-c22c-11e6-ab89-0242fb4b45f0",
"name": "r6g53z",
"link": {
"rel": "self",
"href": "https://172.23.166.145:9060/ers/config/guestuser/a6392010-c22c-11e6-ab89-0242fb4b45f0",
"type": "application/xml"
}
},
{
"id": "a63cc991-c22c-11e6-ab89-0242fb4b45f0",
"name": "v3u8h8",
"link": {
"rel": "self",
"href": "https://172.23.166.145:9060/ers/config/guestuser/a63cc991-c22c-11e6-ab89-0242fb4b45f0",
"type": "application/xml"
}
}
]
}
}