Masscan::Client

Perl interface for running masscan scans and parsing JSON results.

Author and maintainer: Heitor Gouvea <hgouvea@cpan.org>

Requirements

Install

From CPAN:

cpanm Masscan::Client

From a local release tarball:

cpanm ./Masscan-Client-0.2.tar.gz

Quick Start

use strict;
use warnings;
use Masscan::Client;

my $scanner = Masscan::Client -> new(
    hosts => ['127.0.0.1'],
    ports => [80, 443],
);

$scanner -> add_argument('--rate 10000');

my $ok = $scanner -> scan;
if ($ok) {
    my $result = $scanner -> scan_results;
    print "Up hosts: " . $result -> {masscan} -> {scan_stats} -> {up_hosts} . "\n";
}

Full Example

use strict;
use warnings;
use Data::Dumper;
use Masscan::Client;

my $scanner = Masscan::Client -> new(
    hosts => ['10.0.0.1', 'scanme.nmap.org'],
    ports => [22, 80, '443', '8000-8100'],
);

$scanner -> verbose(1);
$scanner -> sudo(1);
$scanner -> add_argument('--banners');
$scanner -> add_argument('--rate 100000');

my $success = $scanner -> scan;
if (!$success) {
    die "masscan command failed\n";
}

my $data = $scanner -> scan_results;
print Dumper($data);

What scan_results Returns

scan_results returns a hash reference with:

Main Methods

Return Values and Failure Behavior

Common failure causes:

Constructor Attributes

Masscan::Client -> new(...) accepts these attributes:

Generated Command Example

You can inspect the exact command generated by the module after calling scan():

use strict;
use warnings;
use Masscan::Client;

my $scanner = Masscan::Client -> new(
    hosts => ['127.0.0.1'],
    ports => [80, 443],
);

$scanner -> add_argument('--rate 10000');
$scanner -> scan;

print $scanner -> command_line . "\n";

Example output:

/usr/bin/masscan --rate 10000 -p 80,443 127.0.0.1

Notes

Privileges and Security

Minimal Verification Script

Use this script to validate that installation and basic execution work:

use strict;
use warnings;
use Masscan::Client;

my $scanner = Masscan::Client -> new(
    hosts => ['127.0.0.1'],
    ports => [80],
);

$scanner -> add_argument('--rate 1000');

my $ok = $scanner -> scan;
if (!$ok) {
    die "scan failed\n";
}

my $result = $scanner -> scan_results;
print "total_hosts=" . $result -> {masscan} -> {scan_stats} -> {total_hosts} . "\n";
print "up_hosts=" . $result -> {masscan} -> {scan_stats} -> {up_hosts} . "\n";

License

This distribution is free software; you can redistribute it and/or modify it under the same terms as Perl 5.