Fortigate ¹æÈ­º® Á¤Ã¥ ¿¢¼¿ÆÄÀÏ·Î º¯È¯(CSV)

   Á¶È¸ 24212   Ãßõ 0    

http://www.aiocp.co.kr (9299)
https://www.ehostidc.co.kr/cscenter/consulting.php (8817)





Fortigate 0169;화ǣ17; 1221;책1012; Ꮘ1;셀파1068;(.csv)/196; 변환Ȣ16;lj16; 0169;법1077;니다.
해NJ17; 매뉴얼1008; perl 스크립트를 1060;용Ȣ16;여 변환Ȣ16;lj16; 0169;식1060;며 윈도우용 perl 프/196;그ǖ16;1064; Strawberry Perl 1012; 설치Ȣ16;여 사용합니다.
(보통 리눅스 계열 OS1032; ᅆ1;우 perl 1060; 기본1004;/196; 설치.104;Ǻ12; 1080;Ǻ12;서 리눅스 계열 OS를 가1648;고 1080;1012; ᅆ1;우 해NJ17; OS/196; 스크립트 0143; 1221;책 파1068;1012; 복사Ȣ16;여 perl 스크립트를 실행, 생성.108; 파1068;1012; 다운/196;드해도 .121;니다.)

테스트 환ᅆ1; : windows 10 / fortigate 100D


1. Strawberry Perl 설치






- https://strawberryperl.com 에서 프/196;그ǖ16; 다운 0143; 설치

- 기본 설치 시 c:\Strawberry\perl\bin> 위치에서 perl 명/16112; 실행 가능




2. 스크립트 파1068; 생성


#!/usr/bin/perl

#


my $output = "policies-out.csv";


my $policyid = 0;

my $setting = "";

my %policies;

my %seen;

my $in_policy_block = 0;

my @order_keys;

my $order_key = 0;


open(OUTFILE,">$output") || die "Can't open file $output: $!\n";


while (<>) {

&#160; &#160; &#160; &#160; &#160; &#160;if ($in_policy_block) {

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;if (/^\s*edit\s+(\d+)/i) {

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; # start of new policy

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; $policyid = $1;

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;} elsif (/^\s*set\s+(\S+)\s+(.*)$/i) {

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; # it's a setting

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; my ($key,$value) = ($1,$2);

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; $value =~ tr/\"\015\012\n\r//d;

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; $order_keys[$order_key++] = $key unless $seen{$key}++;

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; $policies{$policyid}{$key} = $value;

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;} elsif (/^\s*end/i) {

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; $in_policy_block = 0;

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;}

&#160; &#160; &#160; &#160; &#160; &#160;} elsif (/^\s*config firewall policy/i) {

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;$in_policy_block = 1;

&#160; &#160; &#160; &#160; &#160; &#160;}

}


# print out our header

print OUTFILE "id";

foreach my $key (@order_keys) {

&#160; &#160; &#160; &#160; &#160; &#160;print OUTFILE ",$key";

}

print OUTFILE "\n";


# now print out each record

foreach my $policy (sort keys %policies) {

&#160; &#160; &#160; &#160; &#160; &#160;print OUTFILE "$policy";

&#160; &#160; &#160; &#160; &#160; &#160;foreach my $key (@order_keys) {

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;if (defined($policies{$policy}{$key})) {

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; print OUTFILE ",$policies{$policy}{$key}";

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;} else {

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; print OUTFILE ",";

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;}

&#160; &#160; &#160; &#160; &#160; &#160;}

&#160; &#160; &#160; &#160; &#160; &#160;print OUTFILE "\n";

}



close(OUTFILE);



- 메모1109;1012; 사용Ȣ16;여 상단 스크립트를 복사Ȣ16;고 “policy_script.pl̶1; /196; 1200;1109;

- c:\Strawberry\perl\bin> 위치/196; 스크립트 파1068; 1060;ᇼ1;




3. 0169;화ǣ17; 1221;책1012; 메모1109;에 복사









- Fortigate를 ssh/196; 1217;속, “show firewall policy̶1; 명/16112; 1077;/141; 후 출/141;.104;lj16; 내용1012; 메모1109;에 복사
(Fortigate Config파1068; 다운 후 파1068; 내 “config firewall policy̶1; 1460; 포함 Ȣ16;단1032; 1221;책1012; 복사해도 .121;니다.)

- 메모1109;1012; “policy_rule.txt̶1;/196; 1200;1109;

- c:\Strawberry\perl\bin> 위치/196; 1221;책 파1068; 1060;ᇼ1;




4. Perl 스크립트 실행










- c:\Strawberry\perl\bin> 위치에서 “perl policy_script.pl policy_rule.txt̶1; 명/16112; 실행

- policies-out.csv 파1068;1060; 생성.120;

- csv 파1068; 확1064;





https://www.aiocp.co.kr/ ( 딥러닝,머신러닝 서버 판매 ,컨설팅) https://bigbangcloud.co.kr/ ( GPU 클라우드 서비스) ::: AI 서버의 모든것 ::: 인공지능의 시작~ (주)이호스트ICT
FortiOS 6.4.9 ºÎÅÍ json, csv export ±â´É µé¾î°¡±â ½ÃÀÛ Çß½À´Ï´Ù^^


Á¦¸ñPage 4/26
2022-12   33569   µö·¯´×¼­¹ö
2022-11   37115   µö·¯´×¼­¹ö
2022-11   44121   µö·¯´×¼­¹ö
2022-11   48621   ocarina
2022-10   42855   µö·¯´×¼­¹ö
2022-10   36142   È­Á¤Å¥»ï
2022-10   34507   µö·¯´×¼­¹ö
2022-10   21294   ¹Ú¹®Çü
2022-09   16401   µö·¯´×¼­¹ö
2022-09   33077   µö·¯´×¼­¹ö
2022-08   24937   ¹ÌÄ£°¨ÀÚ
2022-08   26649   ÄíÀö
2022-08   30565   µö·¯´×¼­¹ö
2022-08   36704   ¹Ú¹®Çü
2022-07   23287   µö·¯´×¼­¹ö
2022-07   24213   µö·¯´×¼­¹ö
2022-06   24338   µö·¯´×¼­¹ö
2022-06   28710   µö·¯´×¼­¹ö
2022-05   29891   È­Á¤Å¥»ï
2022-05   32082   µö·¯´×¼­¹ö