#!/usr/bin/perl -w use strict; # always use Socket; my @host_array = qw( www.slashdot.org www.deja.com www.perlmonks.org ); my $proto = 'tcp'; my $port = 80; foreach my $host (@host_array) { # open the socket socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname($proto)) or die "Unable to create socket!\n"; # connect to remote site my $isUp = connect(SOCK, sockaddr_in($port, inet_aton($host))); # print what we found out print "$host is "; print "NOT " unless $isUp; print "reachable.\n"; }