Leser: 25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/perl use strict; use warnings; use IO::Socket; my $host='127.0.0.1'; my $port='80'; if(IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port )) { print "Verbindung hergestellt\n"; } else { print "Verbindung kam nicht zustande\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
#!/usr/bin/perl # vi: set ts=4 sw=4 sts=2 et: use strict; use warnings; use IO::Socket; use File::Basename qw( basename ); # Author: linuxer <winfree@gmx.de> # Date: 22. Juli 2008 # Description: # checks if remote host listens to specified port(s) #> global variables (the less you use, the better the script) #> -------------------------------------------------------------------------- our $VERSION = '0.34'; #> sub routines #> -------------------------------------------------------------------------- { my $failed = 0; sub checkport { my $host = shift; my $port = shift; my $socket = IO::Socket::INET->new( PeerAddr => $host, PeerPort => $port, Protocol => q{tcp}, Timeout => 2, ); if ( $socket ) { close $socket; return qq{+ $host tcp/$port reached\n}; } else { $failed++; return qq{- $host tcp/$port NOT reached: $!\n}; } } # sub grand_final { print qq{$failed not reached\n} if ( $failed ); exit $failed; } # } sub print_help { my $program = basename $0; print <<"HELP"; SYNOPSIS $program remote_host tcp_port [tcp_port ...] DESCRIPTION This script simply tries to open a connection to the remote host and the specified port(s). It is meant as a simple check, whether a remote host listens to a specific port (and is reachable). In case the specified port can't be reached, the script generates an error message with a reason. This reason is taken from the system itself. Depending on the system, this reason may be usable (linux; connection refused / timed out) or not (windows; connect failed). EXAMPLE $program localhost 22 checks if localhost is reachable on tcp port 22. HELP } # #> main script #> -------------------------------------------------------------------------- my $remote = shift @ARGV; if ( !$remote or $remote =~ m/\A-/ or ! @ARGV ) { print_help(); exit 0; } # for my $port ( @ARGV ) { print checkport( $remote, $port ) if $port =~ m/\A \d+ \z/x; } grand_final(); __END__
2009-11-27T13:56:39 DonKnilchDanke erstmal für die Hinweise.
Was ich noch vergessen habe: Der Check soll nicht protokolliert werden, da es sich um ein Monitoring handelt, welches relativ häufig ausgeführt wird. Daher darf keine richtige Verbindung aufgebaut werden sondern es soll nur ein kurzer Check erfolgen, ob das Programm läuft. Bei Nmap ist das quasi der Stealth-Mode.
Ist sowas mit einer dieser Varianten machbar?