Fortigate ¹æȺ® Á¤Ã¥ ¿¢¼¿ÆÄÀÏ·Î º¯È¯(CSV)
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 설치 |
- 기본 설치 시 c:\Strawberry\perl\bin> 위치에서 perl 명/161;Ǻ12; 실행 가능 |
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); |
- c:\Strawberry\perl\bin> 위치/196; 스크립트 파1068; 1060;ᇼ1; |
3. 0169;화ǣ17; 1221;책1012; 메모1109;에 복사 |
- 메모1109;1012; “policy_rule.txt̶1;/196; 1200;1109; - c:\Strawberry\perl\bin> 위치/196; 1221;책 파1068; 1060;ᇼ1; |
4. Perl 스크립트 실행 |
- policies-out.csv 파1068;1060; 생성.120; - csv 파1068; 확1064; |
|