[perl] 포트 체크 스크립트
일전에 일하다 필요해서 급조로 짠 초간단 펄 스크립트..
응용하면 쓸만한 스크립트일듯.
===== 이하 config.ini 파일 =====
<FONT color=#0000ff>
; 체크할 대상의 ip 설정, 대상이 여러개의 호스트일 경우 구분자는 쉼표
Dest_Server_IP=127.0.0.1
[Dest_Server_Port]
; 체크할 대상의 포트 설정
PORT=80
[Check_Time]
; 포트 체크시 타임아웃 설정
TIME=0.5</FONT>
</FONT>
===== 이하 Check_port.pl 파일=====
<FONT color=#0000ff>
<FONT color=#0000ff>#!/usr/bin/perl </FONT>
<FONT color=#0000ff># by netggio
### </FONT><FONT color=#0000ff>http://netggio.pe.kr</FONT>
<FONT color=#0000ff>use strict;
use warnings;
use CGI;
use Net::Ping;
use LWP::Simple;
use Config::IniFiles;
my $ip ;
; config.ini 파일 위치 기입
my $file = “/usr/local/tools/script/config.ini”;
my $ini = Config::IniFiles->new(
-file => $file
) or die “Could not open $file!”;</FONT>
<FONT color=#0000ff>my $Client_config=$ini->val(‘Dest_Server’,’Dest_Server_IP’ );
my @Dest_host=split(/,/, $Client_config);</FONT>
<FONT color=#0000ff>my $Client_port_config=$ini->val(‘Dest_Server_Port’,’PORT’ );</FONT>
<FONT color=#0000ff>my $CHECK=$ini->val(‘Check_Time’,’TIME’ );</FONT>
<FONT color=#0000ff>foreach my $ip (@Dest_host)</FONT>
<FONT color=#0000ff>{
my $p = Net::Ping->new(‘tcp’, $CHECK);
$p->tcp_service_check(1);
my $host = “$ip”;
$p->{‘port_num’} = “$Client_port_config”;
print “$host –> port $Client_port_config is “,</FONT>
<FONT color=#0000ff> ($p->ping($host) ? “<font color=’blue’>up</font color>
” : “<font color=’red’>down</font color>
”);</FONT>
<FONT color=#0000ff>}
</FONT>
</FONT>===================================
간단 사용법
perl Check_port.pl > Result.html
html로 결과 저장됨.