How to write iptables commands in perl ?

Hi guys. I’m new to perl. I’ve worked with iptables in shell, but now I need to write an iptables command with perl. here is my code that I’ve tried but it didn’t work :

#!/usr/bin/perl
print "Content-type: text/html

";
iptables("-t nat -A PREROUTING -d 192.168.10.2 -p tcp --dport 80 -j DNAT --to-destination 192.168.0.1");

anyone could help ?

#!/usr/bin/perl
system("iptables blah blah blah");

Naturally you should do more, e.g. check the return status, etc.

thnx but this system() function didn’t work. :frowning: How can I check retrieved values ?

Probably because iptables is in /usr/sbin, so you should write system("/usr/sbin/iptables …");

You can get the return value with $status = system("…"); See the perlfunc man page for the meaning of the return value.

thank you.