Support Forum
The Forums are a place to find answers on a range of Fortinet products from peers and product experts.
Dano
New Contributor

Add mulitple static routes

Hello all,

 

I am new to the forum as well as new to Fortigate.  I am looking at switching over from another firewall vendor and there is no converter for them.  I need to add about 140 static routes and I am not looking forward to manually entering all of them. I wanted to know if anyone has a batch file or script that will parse a text file and output it to a file and I can paste into the CLi.  Any help would be greatly appreciated!

 

Thank you in advance!!

1 Solution
pmandava_FTNT

Hi Dano,

 

If you can share the text file from the other firewall containing the routes, I might be able to provide a Notepad++ macro to perform the conversion.

 

-prithvi

View solution in original post

5 REPLIES 5
ede_pfau
Esteemed Contributor III

I've stirred up a quick hack to get this done. It's a Windows command script, reading a plain text file in CSV format.

@echo off

rem create FortiGate batch script for static routes
 
set infile=%~1
if not exist %infile% (
   echo Usage: create_stat_routes inputfile ^> output.bcmd
   echo input file format^: network_address,network_mask,gateway,interface_name,^[distance^]
   goto :EOF
)
 
echo config router static
 
FOR /F "tokens=1-5 delims=," %%A IN (%infile%) DO (
   echo edit 0
   echo set dst %%A %%B
   echo set gateway %%C
   echo set device "%%D"
   if not %%E.==. echo set distance %%E
   echo next
)
 
echo end and a sample input file would look like
192.168.47.0,255.255.255.0,192.168.1.1,internal,10 
10.16.99.0,255.255.240.0,172.16.23.254,vl_company,20
 

Ede

"Kernel panic: Aiee, killing interrupt handler!"
Ede"Kernel panic: Aiee, killing interrupt handler!"
pmandava_FTNT

Hi Dano,

 

If you can share the text file from the other firewall containing the routes, I might be able to provide a Notepad++ macro to perform the conversion.

 

-prithvi

Dano

Hi prithvi,   Thank you for the offer, unfortunately some of the routes are on a secured network and I am not allowed to share the addresses out. Otherwise I would take you up on the offer.   Dano
Dano
New Contributor

I would like to thank all that replied.  ede_pfau provided a script for me that was able to create the routes from my extract out of the old firewall.

 

Thanks so much!

ede_pfau
Esteemed Contributor III

Yep, here's the version that actually WORKS...

Version:0.9 StartHTML:-1 EndHTML:-1 StartFragment:128 EndFragment:3427 StartSelection:128 EndSelection:3427

@echo off
 
rem create FortiGate batch script for static routes
rem 2020-02-28 info@beneicke-edv.de, ede_pfau@forum.fortinet.com
 
setlocal EnableDelayedExpansion EnableExtensions
 
if not exist "%~1" goto :usage
for %%F in ("%~1") do set infile="%%~nxF"
 
echo config router static
 
FOR /F "tokens=1-5 delims=," %%A IN ('type %infile%') DO (
echo edit 0
echo set dst %%A %%B
echo set gateway %%C
echo set device "%%D"
if not %%E.==. echo set distance %%E
echo next
)
 
echo end
 
rem output example
rem from input: 192.168.47.0,255.255.255.0,192.168.1.1,internal,10
rem config router static
rem edit 0
rem set dst 192.168.47.0 255.255.255.0
rem set gateway 192.168.1.1
rem set device "internal"
rem set distance 10
rem next
rem end
 
goto :EOF
 
rem ---------------------
 
:usage
echo Usage: %0 inputfile ^> output.bcmd
echo input file format^: network_address,network_mask,gateway,interface_name^[,distance^]
goto :EOF


Ede

"Kernel panic: Aiee, killing interrupt handler!"
Ede"Kernel panic: Aiee, killing interrupt handler!"
Labels
Top Kudoed Authors