• perl 根据函数返回值判断


    ###############################################
    
    jrhmpt01:/root/sbin# cat a3.pl 
    use IO::Socket;
    $server='121.40.167.35';
    $port=8081;
    $sock = IO::Socket::INET->new(PeerAddr => $server,
                                  PeerPort => $port,
                                  Proto => 'tcp')  ;
    print "$sock is $sock
    ";
    jrhmpt01:/root/sbin# perl a3.pl 
    $sock is IO::Socket::INET=GLOB(0x1a9d0d0)
    
    
    jrhmpt01:/root/sbin# cat a3.pl 
    use IO::Socket;
    $server='121.40.167.35';
    $port=8082;
    $sock = IO::Socket::INET->new(PeerAddr => $server,
                                  PeerPort => $port,
                                  Proto => 'tcp')  ;
    print "$sock is $sock
    ";
    jrhmpt01:/root/sbin# perl a3.pl 
    $sock is 
    
    #######################################################
    jrhmpt01:/root/sbin# cat check_port.pl 
    use IO::Socket;
    ##监控8081
    sub check_server_alive {
         ( $server, $port ) = @_;
    $sock = IO::Socket::INET->new(PeerAddr => $server,
                                  PeerPort => $port,
                                  Proto => 'tcp');
    if (defined($sock)){return 0}else{return 100};  
    };
    $server='121.40.167.35';
    $port=8081;
    $result =check_server_alive($server,$port);
    print "$result is $result
    ";
    
    
    jrhmpt01:/root/sbin# perl check_port.pl 
    $result is 0
    
    
    jrhmpt01:/root/sbin# cat check_port.pl 
    use IO::Socket;
    ##监控8081
    sub check_server_alive {
         ( $server, $port ) = @_;
    $sock = IO::Socket::INET->new(PeerAddr => $server,
                                  PeerPort => $port,
                                  Proto => 'tcp');
    if (defined($sock)){return 0}else{return 100};  
    };
    $server='121.40.167.35';
    $port=8082;
    $result =check_server_alive($server,$port);
    print "$result is $result
    ";
    
    jrhmpt01:/root/sbin# perl check_port.pl 
    $result is 100
    

  • 相关阅读:
    轻院:2211: 小明的有趣回文数
    轻院:2209: 小明找整数
    轻院:2206: 小明发福利
    轻院:2207: 小明被提问
    2135: 这里是天堂!
    牛客小白月赛2:文
    轻院2261: flower
    问题 I: 堆
    SharePoint Server 2010安装图解
    Microsoft Windows Sharepoint Services V3.0 安装图示
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351441.html
Copyright © 2020-2023  润新知