Scripts to migrate hosts from ASA to Fortigate

For my job I am in the process of migrating from an ASA to a FortiGate firewalls. Part of this has been moving the configuration that we already have in place on the ASA and translating it too FortiGate. I needed to convert several address lists. Some of those address lists where hundreds of addresses long and I didn’t want to type those in. So I started using my python skills to build out the configuration by taking in a list of the ip addresses and then outputting the configuration needed for the FortiGate firewall.

Here is the current version of that script:

# variables needed througout:
file = input(“Name of file? “)
title = input(“Name of hosts and group? “)

addresses = open(file, “r”)

print(“config firewall address”)

incr = 1
host_entries = ‘set member’
for address in addresses:
    address = address.rstrip(‘\n’)
    print(‘edit “H_’ + title + str(incr) + ‘”’)
    host_entries = (host_entries + (‘ “H_’ + title + str(incr) + ‘”’))
    print(“set subnet ” + address + ” 255.255.255.255”)
    print(“next”)
    incr = (incr + 1)

print(‘end’)
print(“config firewall addrgrp”)
print(‘edit “G_’+ title + ‘”‘)
print(host_entries)
print(‘next’)
print(‘end’)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.