Blz?!<br>č o seguinte, falta do q fazer é f... estou fazendo um script q facilita a leitura de arquivo de regras de firewall... é bem básico, se alguém quiser me ajudar a terminar, eu agradeceria muito...<br>segue o script:
<br><br><code><br><br>#!/usr/bin/perl -n<br><br><span>BEGIN{<br></span><span>$int = '\$INT';<br>$ext = '\$EXT';<br></span><span>%conhecido = (<br>                "-t" => "filter|nat|mangle" ,
<br>                 "-[ADIR]" => "INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING" ,<br>                "-p" => "\!?(?:tcp|udp|icmp)(?:,(?:tcp|udp|icmp)){0,3}" ,<br>                "-s" => ".*?" ,
<br>                "-d" => ".*?" ,<br>                "-j" => "ACCEPT|DROP|LOG|REJECT|QUEUE|RETURN|DNAT|SNAT|MASQUERADE",<br>                "-g" => ".*?" ,
<br>                "-i" => ".*?" ,<br>                "-o" => ".*?" ,<br>                "--(?:destination-|source-|[ds])port" => "\\d+?|\\\$.*?" ,
<br>                "--to(?:-destination|-source)?" => ".*?" ,<br>        );<br>}<br><br>%hash=();<br><br>next if /^#/;<br><br>s/([^\\])#.*$/$1/g;<br>s/(--[ds])(?:estination|ource)-port/$1port/g;
<br>s/(--to)-[ds](?:estinadion|ource)/$1/g;<br><br>$iptables = "\\\$".$1 if /^\s*(.*?)=.*?iptables.*?$/;<br>$iptables ||= "iptables";<br><br>if(/^\s*$iptables/)<br>{<br> print("Apaga a tablela ", $1 || "filter", $/), next if /(?:-t\s+(filter|nat|mangle)\s+)?-[FX]\s+/;
<br> s/$int/interna/g;<br> s/$ext/externa/g;<br> %hash = /(-.+?)\s+(?:(.+?)\s+)?/g;<br> CHAVE: for $chave (keys %hash)<br> {<br>         undef $sim;<br>         for $conh (keys %conhecido)<br>         {<br>                 $value = $conhecido{$conh};
<br>                 if($chave =~ /^$conh$/){<br>                         $sim = 1, next CHAVE if $hash{$chave} =~ /^$value$/;<br>                 }<br>         }<br>         print "Regra desconhecida na linha $.\n";<br>         last CHAVE;<br> }<br> next unless $sim;
<br> if($hash{"-t"} eq "nat")<br> {<br>         print "Porta ", $hash{"--dport"} || $hash{"--sport"}, ", redirecionad", ($hash{"-A"} eq "PREROUTING"?"o destino":"a origem"), " para o IP ", $hash{"--to"} || $hash{"--to-destination"} || $hash{"--to-source"}, $/ if $hash{"--dport"} || $hash{"--sport"};
<br> }<br> elsif($hash{"-A"} eq "FORWARD")<br> {<br>         print $hash{"-p"}?"Sob o protocolo \"".$hash{"-p"}."\", ":"", $hash{"--dport"}?"porta ".$hash{"--dport"}." da ":"", "interface ", $hash{"-o"}, " para a interface ",$hash{"-i"}, " foi ", ($hash{"-j"} eq "ACCEPT"?"aceito":"negado"), $/ if $hash{"-j"} =~ /ACCEPT|DROP/;
<br> }<br> elsif($hash{"-A"} eq "INPUT")<br> {<br>         print $hash{"-p"}?"Sob o protocolo \"".$hash{"-p"}."\", ":"", $hash{"--dport"}?"porta ".$hash{"--dport"}." ":"", $hash{"-i"}?"para a interface ".$hash{"-i"}:$hash{"-d"}?"para o ip ".$hash{"-d"}:"",$hash{"-s"}?" do ip ".$hash{"-s"}:"", " foi ", ($hash{"-j"} eq "ACCEPT"?"aceito":"negado"), $/ if $hash{"-j"} =~ /ACCEPT|DROP/;
<br> }<br> elsif($hash{"-A"} eq "OUTPUT")<br> {<br>         print $hash{"-p"}?"Sob o protocolo \"".$hash{"-p"}."\", ":"", $hash{"--dport"}?"porta ".$hash{"--dport"}." ":"", $hash{"-o"}?"da interface ".$hash{"-o"}:$hash{"-s"}?"do ip ".$hash{"-s"}:"",$hash{"-d"}?" para o ip ".$hash{"-d"}:"", " foi ", ($hash{"-j"} eq "ACCEPT"?"aceito":"negado"), $/ if $hash{"-j"} =~ /ACCEPT|DROP/;
<br> }<br> elsif($hash{"-F"} || $hash{"-X"})<br> {<br>         print "Apagando as regras da tabela ", $hash{"-t"} || "filter", $/;<br> }<br>}</span><br><br></code>
<br><br>-- <br>[]'s Fernando<br>