我在 perl 上使用 nmap 扫描仪模块在某些主机上执行 nmap。我可以拉出打开的端口,但我也希望能够向端口添加服务,例如 tcp/22 SSH。当我在 linux 机器上运行 nmap 时使用
nmap -sS -p 1-1024 -sV -O --max-rtt-timeout 200ms host.ip
我使用他们的服务打开了所有端口,但是我也无法更改我的 perl 代码来打印服务。我当前的代码:
my $scanner = new Nmap::Scanner;
$scanner->register_scan_started_event(\&scan_started);
$scanner->register_port_found_event(\&port_found);
$scanner->scan('-sS -p 1-1024 -sV -O --max-rtt-timeout 200ms host.ip');
sub scan_started {
my $self = shift;
my $host = shift;
my $hostname = $host->hostname();
my $addresses = join(',', map {$_->addr()} $host->addresses());
my $status = $host->status();
print "$hostname ($addresses) is $status\n";
}
sub port_found {
my $self = shift;
my $host = shift;
my $port = shift;
my $name = $host->hostname();
my $addresses = join(',', map {$_->addr()} $host->addresses());
print "On host $name ($addresses), found ",
$port->state()," port ",
join('/',$port->protocol(),$port->portid()),"\n";
}
我得到的输出是
(host.ip) is up
On host (host.ip), found open port tcp/22
On host (host.ip), found open port tcp/111
如果我能获得与端口一起提供的服务,我将非常感激,就像我手动输入命令时出现的那样。