need help on configuring fortigate firewall CLI code for bulk ipmacbinding by importing a ip/mac entries list file
Question: i am facing a problem in ip/mac binding in fortigate 200d, the thing is i have
a list of 3000 entries of IP/MAC addresses, i have kept them in a csv file.

This is what i am looking for

1.I want to write a code which can import that file

2.I want execute this code snippet inside a loop until all entries are
updated.

    
    
    config firewall ipmacbinding table
    edit <index_int>
        set ip <address_ipv4>
        set mac <address_hex>
        set name <name_str>
        set status {enable}
    end
    

  3. with the help of above code snippet each time i have to manually enter the the IP,MAC and Name values for 3000-times, instead i just want to import a file and from that file values should be added.

  4. In few places i came to know that it can achieved with the help of perl/python script but i am not aware of that.

i googled but i didn't find anywhere about this information, so i hope that i
would get help to get this task done.

Thanks.

Format of CSV File is

    
    
    Index   IP       Mac                name
    1   10.10.17.1  aa:bb:cc:00:11:22   first
    2   10.10.17.2  cc:dd:ee:ff:22:33   second
    3   10.10.17.3  33:44:11:3f:00:88   third
    

[Formal of CSV File](http://i.stack.imgur.com/tj4VP.jpg)


Answer: I have never used the fortigate CLI so i will assume you know how it works and
what to do with it. below is a small attempt that if it doesnt work exactly
will hopefully put you on the correct trail. I have assumed that when you run
the config command, the terminal normally waits for user input. so in this
case the perl script will pipe in that input.

    
    
    use strict;
    use warnings;
    
    my $csv_file = shift;
    open (my $cfh, '<', $csv_file) or die "Unable to open $csv_file: $!";
    my @headers = split (' ', <$cfh>);
    
    while(<$cfh>){
      my %config;
      my @data = split(' ');
      @config{@headers}=@data;
    
      open(my $firewall, '|-', 'config firewall ipmacbinding table') or die "Unable to open 'config firewall ipmacbinding table': $!";
      print $firewall "edit ",$config{'Index'},"\n";
      print $firewall "set ip ",$config{'IP'},"\n";
      print $firewall "set mac ",$config{'Mac'},"\n";
      print $firewall "set name ",$config{'name'},"\n";
      print $firewall "set status {enable}\n";
      print $firewall "end\n";
      close $firewall;
    }
    

the above is written as an attempt to help you get started on how to make this
work. as i said i have no experience with fotigate so you may need to tweek
this a bit.

If i chose to print this just to my terminal screen as output like this

    
    
    use strict;
    use warnings;
    
    my $csv_file = shift;
    open (my $cfh, '<', $csv_file) or die "Unable to open $csv_file: $!";
    my @headers = split (' ', <$cfh>);
    
    while(<$cfh>){
            my %config;
            my @data = split(' ');
            @config{@headers}=@data;
    
            #open(my $firewall, '|-', 'config firewall ipmacbinding table') or die "Unable to open 'config firewall ipmacbinding table': $!";
            print  "config firewall ipmacbinding table\n";
            print  "\tedit ",$config{'Index'},"\n";
            print  "\tset ip ",$config{'IP'},"\n";
            print  "\tset mac ",$config{'Mac'},"\n";
            print  "\tset name ",$config{'name'},"\n";
            print  "\tset status {enable}\n";
            print  "end\n";
            #close $firewall;
    }
    

it produces the following

    
    
    config firewall ipmacbinding table
            edit 1
            set ip 10.10.17.1
            set mac aa:bb:cc:00:11:22
            set name first
            set status {enable}
    end
    config firewall ipmacbinding table
            edit 2
            set ip 10.10.17.2
            set mac cc:dd:ee:ff:22:33
            set name second
            set status {enable}
    end
    config firewall ipmacbinding table
            edit 3
            set ip 10.10.17.3
            set mac 33:44:11:3f:00:88
            set name third
            set status {enable}
    end
    

hopefully this is enough for you to get started.

