-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpingACI.py
39 lines (33 loc) · 1.07 KB
/
pingACI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env Python
#
import requests
import sys
def getAPICCookie(ip_addr, username, password, usetls):
protocol='http'
if usetls:
protocol='https'
url = protocol+'://'+ip_addr+'/api/aaaLogin.xml'
xml_string = "<aaaUser name='%s' pwd='%s'/>" % (username, password)
req = requests.post(url, data=xml_string, verify=False)
rawcookie=req.cookies['APIC-cookie']
return rawcookie
if __name__ == '__main__':
if len(sys.argv) != 5:
ip=raw_input("IP address of APIC? ")
user=raw_input("Admin username? ")
password=raw_input("Password? ")
usetls=raw_input("Use TLS? [y/n] ")
else:
ip,user,password,usetls = sys.argv[1:]
if usetls=='y':
usetls=True
else:
usetls=False
print("User {} logging into APIC {} (TLS: {})".format(user, ip, usetls))
cookie=getAPICCookie(ip, user, password, usetls)
if cookie:
print("Obtained cookie: {}\n".format(cookie))
print("APIC is alive.")
else:
print "That didn't work, we received no response back!"
sys.exit(1)