I assume that it's supposed to be
128.135.75.1
is alive
???
Try removing the newline in this part
@iparray = map $ipnumber. ".$_\n",1..254 ; And adding a newline to
foreach my $host (@iparray) {
if ( $p->ping( $host )){
print " $host is alive\n ";
at the end of that.
Otherwise when it goes to print the host it copies the newline from the original array. And hence the return at the end of the IP Address. So the final product should look like this (Note: I change the ips to match my network)
#!/usr/bin/perl
use warnings;
use Net::Ping;
use Socket;
$ipnumber ="192.168.30";
chomp $ipnumber;
@iparray = map $ipnumber. ".$_",1..254 ;
chomp $ipnumber;
#open (ERRORLOG, ">errorlog");
#open (OFFLINE,">offline");
#open (ONLINE,">online");
my $proto = 'icmp';
my $def_timeout = '5';
my $bytes = '64';
my $p = Net::Ping->new($proto, $def_timeout , $bytes);
foreach my $host (@iparray) {
if ( $p->ping( $host )){
print " $host is alive\n ";
}
#foreach my $host (@iparray) {
# $testing = $p $host;
# print "$testing";
# print "$host offline " unless $p->ping($host,1);
# print "$host online " unless $p->ping($host,0);
# print ERRORLOG "$host offline " unless $p->ping($host,1);
# print OFFLINE "$host"unless $p->ping($host,1);
# print ONLINE "$host online" unless $p->ping($host,0);
}
$p->close();
Sgt
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.