-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetBDGipos.py
68 lines (54 loc) · 1.96 KB
/
getBDGipos.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
#
# cpaggen; PoC-quality; quick and dirty script that does what I need
#
# queries APIC for all fvDB objects and finds bcastP attribute
#
import requests
import sys
import json
from pprint import pprint
http_header={"User-Agent" : "Chrome/17.0.963.46",
"Accept" : "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,text/png,*/*;q=0.5",
"Accept-Language" : "en-us,en;q=0.5",
"Accept-Charset" : "ISO-8859-1",
"Content-type": "application/x-www-form-urlencoded"
}
def getAPICCookie(ip_addr, username, password):
url = 'http://'+ip_addr+'/api/aaaLogin.xml'
http_header["Host"]=ip_addr
xml_string = "<aaaUser name='%s' pwd='%s'/>" % (username, password)
req = requests.post(url, data=xml_string, headers=http_header, verify=False)
rawcookie=req.cookies['APIC-cookie']
return rawcookie
def sendAPICRequest(ip_addr, cookie, apicurl):
url = 'http://'+ip_addr+apicurl
http_header["Host"]=ip_addr
cookies = {}
cookies['APIC-cookie'] = cookie
req = requests.get(url,headers=http_header,cookies=cookies)
return req.text
def main():
if len(sys.argv) != 4:
ip=raw_input("IP address of APIC? ")
user=raw_input("Admin username? ")
password=raw_input("Password? ")
else:
ip,user,password = sys.argv[1:]
cookie=getAPICCookie(ip, user, password)
if cookie:
print "We have a cookie:\n %s\n" % cookie
apicurl='/api/node/class/fvBD.json'
r=sendAPICRequest(ip, cookie, apicurl)
if r:
parsed_json = json.loads(r)
for bd in parsed_json['imdata']:
bdDN = bd['fvBD']['attributes']['dn']
bcastP = bd['fvBD']['attributes']['bcastP']
print("{0} uses {1}").format(bdDN, bcastP)
else:
print "That didn't work, we received no response back!"
else:
print "Login error."
if __name__ == '__main__':
sys.exit(main())