John W. Krahn am Sonntag, 14. Mai 2006 01.03: > D. Bolliger wrote: > > John W. Krahn am Sonntag, 14. Mai 2006 00.11: > >>Or you could "cheat" and let Getopt::Long parse it for you: > >> > >>$ perl -MGetopt::Long -MData::Dumper -e' > >>$_ = q[iptables -A INPUT -p tcp -s 123.45.678.90 --dport 22 -j ACCEPT]; > >>my %h; > >>{ local @ARGV = split; > >> GetOptions( \%h, "A=s", "p=s", "s=s", "dport=i", "j=s" ); > >> } > >>print Dumper \%h; > >>' > >>$VAR1 = { > >> 'A' => 'INPUT', > >> 'p' => 'tcp', > >> 's' => '123.45.678.90', > >> 'j' => 'ACCEPT', > >> 'dport' => 22 > >> }; > > > > The disadvantage may be that it accepts wrong syntax like -ptcp (see > > remark above), but the idea is great! > > $ perl -MGetopt::Long -MData::Dumper -e' > $_ = q[iptables -A INPUT -ptcp -s 123.45.678.90 --dport 22 -j ACCEPT]; > my %h; > Getopt::Long::Configure( "bundling_override" ); > { local @ARGV = split; > GetOptions( \%h, "A=s", "p=s", "s=s", "dport=i", "j=s" ); > } > print Dumper \%h; > ' > $VAR1 = { > 'A' => 'INPUT', > 'p' => 'tcp', > 's' => '123.45.678.90', > 'j' => 'ACCEPT', > 'dport' => 22 > };
Hello John, I seem to have been unclear, sorry for that. With "it accepts wrong syntax" I meant wrong syntax for iptables: # iptables -A INPUT -p tcp -s 192.158.1.10 --dport 22 -j ACCEPT # iptables -A INPUT -ptcp -s 192.158.1.10 --dport 22 -j ACCEPT iptables v1.3.4: unknown protocol `-ptcp' specified Try `iptables -h' or 'iptables --help' for more information. I may be missing something, of course. Dani -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>