AnsweredHot!Add mulitple static routes

Author
Dano
New Member
  • Total Posts : 3
  • Scores: 0
  • Reward points: 0
  • Joined: 2020/02/23 09:51:29
  • Status: offline
2020/02/23 10:07:09 (permalink)
0

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
ede_pfau
Expert Member
  • Total Posts : 6241
  • Scores: 522
  • Reward points: 0
  • Joined: 2004/03/09 01:20:18
  • Location: Heidelberg, Germany
  • Status: offline
Re: Add mulitple static routes 2020/02/23 11:47:34 (permalink)
0
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!"
#2
pmandava_FTNT
New Member
  • Total Posts : 11
  • Scores: 2
  • Reward points: 0
  • Joined: 2018/10/12 00:24:40
  • Status: offline
Re: Add mulitple static routes 2020/02/24 11:49:02 (permalink) ☼ Best Answerby Dano 2020/02/27 07:08:28
0
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
#3
Dano
New Member
  • Total Posts : 3
  • Scores: 0
  • Reward points: 0
  • Joined: 2020/02/23 09:51:29
  • Status: offline
Re: Add mulitple static routes 2020/02/27 07:11:50 (permalink)
0
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
#4
Dano
New Member
  • Total Posts : 3
  • Scores: 0
  • Reward points: 0
  • Joined: 2020/02/23 09:51:29
  • Status: offline
Re: Add mulitple static routes 2020/02/28 09:46:20 (permalink)
0
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!
#5
ede_pfau
Expert Member
  • Total Posts : 6241
  • Scores: 522
  • Reward points: 0
  • Joined: 2004/03/09 01:20:18
  • Location: Heidelberg, Germany
  • Status: offline
Re: Add mulitple static routes 2020/02/28 10:52:21 (permalink)
0
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!"
#6
Jump to:
© 2020 APG vNext Commercial Version 5.5