寻找匹配的 `' 时出现意外的 EOF '

发布于 2024-12-03 22:33:14 字数 3347 浏览 1 评论 0原文

#!/usr/bin/perl
use warnings;
while(1){
system ( "dialog --menu Customize 30 80 60 "
        . "'Show rules' 'Show all the current rules' "
        . "'Flush rules' 'Flush all the tables' "
    . "Allow IP' 'Block all except one IP' "
    . "'Block IP' 'Block all the packets from an IP' "
    . "'Block MAC' 'Block using the hardware address' "
        . "'Private networking' 'Allow only one network and block other networks' "
    . "'Allow lo' 'Allow local network interface' "
    . "'Save' 'Save customized rules' "
    . "'Exit' 'Close the program' "
        . "'more options' '........' 2> /tmp/customize.txt");

open FILE4, "/tmp/customize.txt" or die $!;
chomp(my $customize = <FILE4>);
        #SHOW RULES
                if($customize =~ /Show rules/){
        `iptables -nvL | tee /tmp/nvl.txt`;
                system ("dialog --textbox /tmp/nvl.txt 22 70");
                }
        #FLUSH RULES
        elsif($customize =~ /Flush rules/){
        `iptables -F`;
        system ("dialog --infobox 'All tables have been flushed.' 05 35");
        sleep 2;
        }
        #ALLOW IP
        elsif($customize =~ /Allow IP/){
        system ("dialog --inputbox 'Enter the IP address of the sysetm which you want to allow:' 15 40 2> /tmp/allowIP.txt");
        open FILE7, "/tmp/allowIP.txt" or die $!;
        chomp(my $aip = <FILE7>);
        `iptables -I INPUT -s $aip -j DROP`;
        system ("dialog --infobox 'IP address $aip is allowed and rest are blocked' 05 45");
        sleep 2;
        }
        #BLOCK IP
        elsif($customize =~ /Block IP/){
        system ("dialog --inputbox 'Enter the IP address of the system which you want to block:' 15 40 2> /tmp/blockIP.txt");
        open FILE5, "/tmp/blockIP.txt" or die $!;
        chomp(my $ip = <FILE5>);
        `iptables -A INPUT -s $ip -j DROP`;
        system ("dialog --infobox 'IP address $ip has been blocked!' 05 35");
        sleep 2;
        }
        #PRIVATE NETWORK    
        elsif($customize =~ /Private networking/){
        system ("dialog --inputbox 'Enter the network address which you want to allow (eg. 192.168.0.0/24)' 15 40 2> /tmp/network.txt");
        open FILE6, "/tmp/network.txt" or die $!;
        chomp(my $network = <FILE6>);
        `iptables -I INPUT -s $network -j ACCEPT`;
        system ("dialog --infobox 'Network $network is allowed and rest networks are blocked' 05 35");
        sleep 2;
        }
        #ALLOW LO
        elsif($customize =~ /Allow lo/){
        `iptables -I INPUT -i lo -j ACCEPT`;
        system ("dialog --infobox 'Local interface is allowed.' 05 35");
        sleep 2;
        }
        #SAVE
        elsif($customize =~ /Save/){
        `service iptables save`;
        system ("dialog --infobox 'All rules have been saved successfully' 05 45");
        sleep 2;
        }
        #EXIT
        elsif($customize =~ /Exit/){
        system ("dialog --infobox 'Closing application.' 05 35");
        sleep 2;
        exit 0;
        }
                else{
                        exit;
                }
}

perl 文件.plx

错误

sh: -c: line 0: unexpected EOF while looking for matching `'' 
sh: -c: line 1: syntax error: unexpected end of file

如何解决此错误?

#!/usr/bin/perl
use warnings;
while(1){
system ( "dialog --menu Customize 30 80 60 "
        . "'Show rules' 'Show all the current rules' "
        . "'Flush rules' 'Flush all the tables' "
    . "Allow IP' 'Block all except one IP' "
    . "'Block IP' 'Block all the packets from an IP' "
    . "'Block MAC' 'Block using the hardware address' "
        . "'Private networking' 'Allow only one network and block other networks' "
    . "'Allow lo' 'Allow local network interface' "
    . "'Save' 'Save customized rules' "
    . "'Exit' 'Close the program' "
        . "'more options' '........' 2> /tmp/customize.txt");

open FILE4, "/tmp/customize.txt" or die $!;
chomp(my $customize = <FILE4>);
        #SHOW RULES
                if($customize =~ /Show rules/){
        `iptables -nvL | tee /tmp/nvl.txt`;
                system ("dialog --textbox /tmp/nvl.txt 22 70");
                }
        #FLUSH RULES
        elsif($customize =~ /Flush rules/){
        `iptables -F`;
        system ("dialog --infobox 'All tables have been flushed.' 05 35");
        sleep 2;
        }
        #ALLOW IP
        elsif($customize =~ /Allow IP/){
        system ("dialog --inputbox 'Enter the IP address of the sysetm which you want to allow:' 15 40 2> /tmp/allowIP.txt");
        open FILE7, "/tmp/allowIP.txt" or die $!;
        chomp(my $aip = <FILE7>);
        `iptables -I INPUT -s $aip -j DROP`;
        system ("dialog --infobox 'IP address $aip is allowed and rest are blocked' 05 45");
        sleep 2;
        }
        #BLOCK IP
        elsif($customize =~ /Block IP/){
        system ("dialog --inputbox 'Enter the IP address of the system which you want to block:' 15 40 2> /tmp/blockIP.txt");
        open FILE5, "/tmp/blockIP.txt" or die $!;
        chomp(my $ip = <FILE5>);
        `iptables -A INPUT -s $ip -j DROP`;
        system ("dialog --infobox 'IP address $ip has been blocked!' 05 35");
        sleep 2;
        }
        #PRIVATE NETWORK    
        elsif($customize =~ /Private networking/){
        system ("dialog --inputbox 'Enter the network address which you want to allow (eg. 192.168.0.0/24)' 15 40 2> /tmp/network.txt");
        open FILE6, "/tmp/network.txt" or die $!;
        chomp(my $network = <FILE6>);
        `iptables -I INPUT -s $network -j ACCEPT`;
        system ("dialog --infobox 'Network $network is allowed and rest networks are blocked' 05 35");
        sleep 2;
        }
        #ALLOW LO
        elsif($customize =~ /Allow lo/){
        `iptables -I INPUT -i lo -j ACCEPT`;
        system ("dialog --infobox 'Local interface is allowed.' 05 35");
        sleep 2;
        }
        #SAVE
        elsif($customize =~ /Save/){
        `service iptables save`;
        system ("dialog --infobox 'All rules have been saved successfully' 05 45");
        sleep 2;
        }
        #EXIT
        elsif($customize =~ /Exit/){
        system ("dialog --infobox 'Closing application.' 05 35");
        sleep 2;
        exit 0;
        }
                else{
                        exit;
                }
}

perl file.plx

error:

sh: -c: line 0: unexpected EOF while looking for matching `'' 
sh: -c: line 1: syntax error: unexpected end of file

How do I resolve this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里兽 2024-12-10 22:33:15

此处缺少 '“允许 IP”

Missing ' here: "Allow IP'

梦里兽 2024-12-10 22:33:15

'

. "Allow IP' 'Block all except one IP' "

您忘记了Perl 代码第 7 行的 Allow IP' 之前的

Your forgot a ' in

. "Allow IP' 'Block all except one IP' "

before Allow IP' in line 7 of your Perl code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文