Net Ping External Ping Program Perl 1 usrbinperl
Net: : Ping: : External 모듈을 이용한 Ping Program Perl 프로젝트
소스 1 � #!/usr/bin/perl -w � � use 5. 010; use strict; use Net: : Ping: : External qw (ping); use Switch; � � � � � � my $num_alive = 0; my $alive; my $host; my @hosts; my $class; my $i; my $j; my $k; my $first; my $second; my $third; my $num; print "Usage : (single host) ==> 1 n"; print " (multi host) ==> ~ n"; print " (class host) == A|B|C n"; print " A class == x. 0. 0. 0n"; print " B class == x. x. 0. 0n"; print " C class == x. x. x. 0n"; print "You Want Class : "; chomp ($class = (<STDIN>)); print "Want IP Address : "; chomp ($host = (<STDIN>)); � � � � switch($class) { case "~" { print "Want Number : "; chomp ($num = (<STDIN>)); for ($i=1; $i<=$num; $i++) { $alive = ping(hostname => $host, count =>1, size=> 1, timeout=>1); print "$host is alive!n" if $alive; print "$host is not alive!n" unless $alive; $num_alive++ if $alive; @hosts = split /. / , $host; $third = pop(@hosts); $third += 1; push @hosts, $third; $host = join ". ", @hosts; } }
소스 2 � � � � � � � � � � � case 1{ foreach ($host) { $alive = ping(hostname => $host, count =>1, size=> 1, timeout=>1); print "$host is alive!n" if $alive; $num_alive++ if $alive; } } case /a/i{ for($k=0; $k<=255; $k++) { for($j=0; $j<=255; $j++) { for ($i=0; $i<254; $i++) { $alive = ping(hostname => $host, count =>1, size=> 1, timeout=>1 print "$host is alive!n" if $alive; print "$host is not alive!n" unless $alive; $num_alive++ if $alive; @hosts = split /. /, $host; $third = pop(@hosts); $third += 1; push @hosts, $third; $host = join ". ", @hosts; } @hosts = split /. /, $host; $third = pop(@hosts); $third = 1; $second = pop(@hosts); $second += 1; push @hosts, $second; push @hosts, $third; $host = join ". ", @hosts; } @hosts = split /. /, $host; $third = pop(@hosts); $third = 1; $second = pop(@hosts); $second +=1; push @hosts, $first; push @hosts, $second; push @hosts, $third; $host = join ". ", @hosts; } }
소스 3 � � � � � � � � � � case /b/i{ for($j=0; $j<255; $j++) { for ($i=0; $i<254; $i++) { $alive = ping(hostname => $host, count =>1, size=> 1, timeout=>1); print "$host is alive!n" if $alive; print "$host is not alive!n" unless $alive; $num_alive++ if $alive; @hosts = split /. /, $host; $third = pop(@hosts); $third += 1; push @hosts, $third; $host = join ". ", @hosts; } @hosts = split /. /, $host; $third = pop(@hosts); $third = 1; $second = pop(@hosts); $second += 1; push @hosts, $second; push @hosts, $third; $host = join ". ", @hosts; } } case /c/i{ for ($i=0; $i<=255; $i++) { $alive = ping(hostname => $host, count =>1, size=> 1, timeout=>1); print "$host is alive!n" if $alive; print "$host is not alive!n" unless $alive; $num_alive++ if $alive; @hosts = split /. /, $host; $third = pop(@hosts); $third +=1; push @hosts, $third; $host = join ". ", @hosts; } } } print "$num_alive hosts are alive. n";
사용한 알고리즘 for ($i=1; $i<=255; $i++) { $alive = ping(hostname => $host); print "$host is alive!n" if $alive; print "$host is not alive!n" unless $alive; $num_alive++ if $alive; @hosts = split /. /, $host; $third = pop(@hosts); $third +=1; push @hosts, $third; $host = join ". ", @hosts; }
실행 화면 �Single host �Multi host �Class host
- Slides: 11