-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathasa.py
68 lines (51 loc) · 1.59 KB
/
asa.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
66
67
68
#!/usr/bin/python
# coding : utf-8
'''
Created on 12.10.2018
@author: MBU
'''
if __name__ == '__main__':
pass
import requests
import urllib3
import json
import authentication
import acl
import importlib
importlib.reload(authentication)
importlib.reload(acl)
urllib3.disable_warnings()
IP = '172.16.0.254'
URL = 'https://' + IP
#Gets Token from ASA and stores it in an header.
token = authentication.Token
Header = authentication.Header
#Get all standard IN ACLs from ASA
def get_acl_in(ip):
data_json = None
url = 'https://' + ip + '/api/access/in'
r = requests.get(url, headers = authentication.Header, verify = False)
if(not r):
print("No Data returned")
else:
data_json = r.json()
return data_json
#Get all extended ACLs from ASA
def get_all_ext_acl(ip):
data_json = None
url = 'https://' + ip + '/api/objects/extendedacls'
#Make GET Request to ASA
r = requests.get(url, headers = authentication.Header, verify = False)
#If there is no response, write no data returned
if(not r):
print("No Data returned")
else:
data_json = r.json()
return data_json
#Creates an extended ACL on ASA, needs an Token, IP-Address, a Name and the rule in JSON-Format
def add_ext_acl(ip, aclName, rule ):
data_json = None
#API-URL to add extended ACL Objects
url = 'https://'+ip+'/api/objects/extendedacls/'+aclName+'/aces'
#Make a POST request to ASA API
r = requests.request("POST", url, data=rule, headers=authentication.Header, verify=False)