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>&lt;code&gt;<br><br>#!/usr/bin/perl -n<br><br><span>BEGIN{<br></span><span>$int = &#39;\$INT&#39;;<br>$ext = &#39;\$EXT&#39;;<br></span><span>%conhecido = (<br>                &quot;-t&quot; =&gt; &quot;filter|nat|mangle&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                 &quot;-[ADIR]&quot; =&gt; &quot;INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;,<br>                &quot;-p&quot; =&gt; &quot;\!?(?:tcp|udp|icmp)(?:,(?:tcp|udp|icmp)){0,3}&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,<br>                &quot;-s&quot; =&gt; &quot;.*?&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,
<br>                &quot;-d&quot; =&gt; &quot;.*?&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,<br>                &quot;-j&quot; =&gt; &quot;ACCEPT|DROP|LOG|REJECT|QUEUE|RETURN|DNAT|SNAT|MASQUERADE&quot;,<br>                &quot;-g&quot; =&gt; &quot;.*?&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,
<br>                &quot;-i&quot; =&gt; &quot;.*?&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,<br>                &quot;-o&quot; =&gt; &quot;.*?&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,<br>                &quot;--(?:destination-|source-|[ds])port&quot; =&gt; &quot;\\d+?|\\\$.*?&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;,
<br>                &quot;--to(?:-destination|-source)?&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; &quot;.*?&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;,<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 = &quot;\\\$&quot;.$1 if /^\s*(.*?)=.*?iptables.*?$/;<br>$iptables ||= &quot;iptables&quot;;<br><br>if(/^\s*$iptables/)<br>{<br>&nbsp;&nbsp; print(&quot;Apaga a tablela &quot;, $1 || &quot;filter&quot;, $/), next if /(?:-t\s+(filter|nat|mangle)\s+)?-[FX]\s+/;
<br>&nbsp;&nbsp; s/$int/interna/g;<br>&nbsp;&nbsp; s/$ext/externa/g;<br>&nbsp;&nbsp; %hash = /(-.+?)\s+(?:(.+?)\s+)?/g;<br>&nbsp;&nbsp; CHAVE: for $chave (keys %hash)<br>&nbsp;&nbsp; {<br>        &nbsp;&nbsp; undef $sim;<br>        &nbsp;&nbsp; for $conh (keys %conhecido)<br>        &nbsp;&nbsp; {<br>                &nbsp;&nbsp; $value = $conhecido{$conh};
<br>                &nbsp;&nbsp; if($chave =~ /^$conh$/){<br>                        &nbsp;&nbsp; $sim = 1, next CHAVE if $hash{$chave} =~ /^$value$/;<br>                &nbsp;&nbsp; }<br>        &nbsp;&nbsp; }<br>        &nbsp;&nbsp; print &quot;Regra desconhecida na linha $.\n&quot;;<br>        &nbsp;&nbsp; last CHAVE;<br>&nbsp;&nbsp; }<br>&nbsp;&nbsp; next unless $sim;
<br>&nbsp;&nbsp; if($hash{&quot;-t&quot;} eq &quot;nat&quot;)<br>&nbsp;&nbsp; {<br>        &nbsp;&nbsp; print &quot;Porta &quot;, $hash{&quot;--dport&quot;} || $hash{&quot;--sport&quot;}, &quot;, redirecionad&quot;, ($hash{&quot;-A&quot;} eq &quot;PREROUTING&quot;?&quot;o destino&quot;:&quot;a origem&quot;), &quot; para o IP &quot;, $hash{&quot;--to&quot;} || $hash{&quot;--to-destination&quot;} || $hash{&quot;--to-source&quot;}, $/ if $hash{&quot;--dport&quot;} || $hash{&quot;--sport&quot;};
<br>&nbsp;&nbsp; }<br>&nbsp;&nbsp; elsif($hash{&quot;-A&quot;} eq &quot;FORWARD&quot;)<br>&nbsp;&nbsp; {<br>        &nbsp;&nbsp; print $hash{&quot;-p&quot;}?&quot;Sob o protocolo \&quot;&quot;.$hash{&quot;-p&quot;}.&quot;\&quot;, &quot;:&quot;&quot;, $hash{&quot;--dport&quot;}?&quot;porta &quot;.$hash{&quot;--dport&quot;}.&quot; da &quot;:&quot;&quot;, &quot;interface &quot;, $hash{&quot;-o&quot;}, &quot; para a interface &quot;,$hash{&quot;-i&quot;}, &quot; foi &quot;, ($hash{&quot;-j&quot;} eq &quot;ACCEPT&quot;?&quot;aceito&quot;:&quot;negado&quot;), $/ if $hash{&quot;-j&quot;} =~ /ACCEPT|DROP/;
<br>&nbsp;&nbsp; }<br>&nbsp;&nbsp; elsif($hash{&quot;-A&quot;} eq &quot;INPUT&quot;)<br>&nbsp;&nbsp; {<br>        &nbsp;&nbsp; print $hash{&quot;-p&quot;}?&quot;Sob o protocolo \&quot;&quot;.$hash{&quot;-p&quot;}.&quot;\&quot;, &quot;:&quot;&quot;, $hash{&quot;--dport&quot;}?&quot;porta &quot;.$hash{&quot;--dport&quot;}.&quot; &quot;:&quot;&quot;, $hash{&quot;-i&quot;}?&quot;para a interface &quot;.$hash{&quot;-i&quot;}:$hash{&quot;-d&quot;}?&quot;para o ip &quot;.$hash{&quot;-d&quot;}:&quot;&quot;,$hash{&quot;-s&quot;}?&quot; do ip &quot;.$hash{&quot;-s&quot;}:&quot;&quot;, &quot; foi &quot;, ($hash{&quot;-j&quot;} eq &quot;ACCEPT&quot;?&quot;aceito&quot;:&quot;negado&quot;), $/ if $hash{&quot;-j&quot;} =~ /ACCEPT|DROP/;
<br>&nbsp;&nbsp; }<br>&nbsp;&nbsp; elsif($hash{&quot;-A&quot;} eq &quot;OUTPUT&quot;)<br>&nbsp;&nbsp; {<br>        &nbsp;&nbsp; print $hash{&quot;-p&quot;}?&quot;Sob o protocolo \&quot;&quot;.$hash{&quot;-p&quot;}.&quot;\&quot;, &quot;:&quot;&quot;, $hash{&quot;--dport&quot;}?&quot;porta &quot;.$hash{&quot;--dport&quot;}.&quot; &quot;:&quot;&quot;, $hash{&quot;-o&quot;}?&quot;da interface &quot;.$hash{&quot;-o&quot;}:$hash{&quot;-s&quot;}?&quot;do ip &quot;.$hash{&quot;-s&quot;}:&quot;&quot;,$hash{&quot;-d&quot;}?&quot; para o ip &quot;.$hash{&quot;-d&quot;}:&quot;&quot;, &quot; foi &quot;, ($hash{&quot;-j&quot;} eq &quot;ACCEPT&quot;?&quot;aceito&quot;:&quot;negado&quot;), $/ if $hash{&quot;-j&quot;} =~ /ACCEPT|DROP/;
<br>&nbsp;&nbsp; }<br>&nbsp;&nbsp; elsif($hash{&quot;-F&quot;} || $hash{&quot;-X&quot;})<br>&nbsp;&nbsp; {<br>        &nbsp;&nbsp; print &quot;Apagando as regras da tabela &quot;, $hash{&quot;-t&quot;} || &quot;filter&quot;, $/;<br>&nbsp;&nbsp; }<br>}</span><br><br>&lt;/code&gt;
<br><br>-- <br>[]&#39;s Fernando<br>