in reply to port check
toolic's already answered the -> question, so I'll focus on the port scan here.
You can use Nmap::Scanner for this task. I must tell you that while fudging the below example, I found errors in the docs throughout the distribution (I've made myself a reminder and I'll go through it more thoroughly later and patch them). This example is nearly copy and paste from the various SYNOPSIS from the modules.
The most notable err in the docs is the call to get_host_list(). In the docs, they specify gethostlist(), which doesn't exist.
Also, you *must* install nmap before installing Nmap::Scanner, and if you get any weird errors upon running your script, you may need to install XML::SAX::Expat as well (I found that solution in this post, in this thread here on PM).
use strict; use warnings; use Nmap::Scanner; my @systems = qw(localhost other); my $scanner = new Nmap::Scanner; $scanner->tcp_syn_scan; $scanner->add_scan_port('22'); $scanner->add_scan_port('80-82'); for (@systems){ $scanner->add_target($_); } my $results = $scanner->scan; my $hosts = $results->get_host_list; while (my $host = $hosts->get_next) { print "\nOn " . $host->hostname . ": \n"; my $ports = $host->get_port_list; while (my $port = $ports->get_next) { print join(' ', 'Port', $port->portid, 'is in state', $port->state, "\n" ); } } __END__ On localhost: Port 22 is in state open Port 80 is in state closed Port 81 is in state closed Port 82 is in state closed On other: Port 22 is in state closed Port 80 is in state closed Port 81 is in state closed Port 82 is in state closed
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: port check
by deelinux (Novice) on Nov 30, 2015 at 17:19 UTC |