-
Notifications
You must be signed in to change notification settings - Fork 0
/
asa2fmc_object.py
47 lines (41 loc) · 1.25 KB
/
asa2fmc_object.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
#!/usr/bin/python3
import textfsm
import fmc
import ipaddress
import re
import getpass
templatefilename = input("textfsm template:\t")
template = open(templatefilename, 'r')
asaconfigfilename = input("asa config:\t")
filetoread = open(asaconfigfilename,'r')
text = filetoread.read()
re_table = textfsm.TextFSM(template)
data = re_table.ParseText(text)
# connect to FCM
#reload(fmc)
ip = input("FMC IP:\t")
user = input("FMC username:\t")
password = getpass.getpass("FMC password:\t")
f = fmc.Fmc(ip,user,password)
print ("CONNECTING TO FMC...")
f.connect()
print ("ADDING OBJECTS...")
h = 0
n = 0
for d in data:
# if it is an host use /32 subnet
if d[0] == 'network' and d[2]:
print ("ADD HOST\t"+str(d))
f.addHost(d[1],d[2],d[5])
h+=1
if d[0] == 'network' and d[3]:
print ("ADD NETWORK\t"+str(d))
# convert to prefixlen - fmc does not support subnet mask
network=ipaddress.IPv4Network(re.sub("\s","/",d[3])).with_prefixlen
f.addNetwork(d[1],network,d[5])
n+=1
print ("TOTAL HOSTS\t"+str(h))
print ("TOTAL NETWORKS\t"+str(n))
print ("TOTAL OBJECTS\t"+str(h+n))
# textfsm template header
# ['type', 'name', 'host', 'subnet', 'service', 'description']