NAME

NetworkInfo::Discovery::Scan - host/port scanner

SYNOPSIS

use NetworkInfo::Discovery;
use NetworkInfo::Discovery::Register;
use NetworkInfo::Discovery::Scan;

my $disc = new NetworkInfo::Discovery::Register (
    'file' => '/tmp/scan.register',
    'autosave' => 1
    )
    || warn ("failed to make new obj");

my $scan = new NetworkInfo::Discovery::Scan (
    hosts=>["localhost", "127.0.0.1"],
    ports=>[53,99,1000..1004],
    timeout=>1,
    'wait'=>0,
    protocol => 'tcp'
);

$scan->do_it();
$disc->add_interface($_) for ($scan->get_interfaces);

foreach my $h ($scan->get_interfaces) {
    print $h->{ip} . "\n";
    print "    has tcp ports: " . join(',',@{$h->{tcp_open_ports}}) . "\n" if (exists $h->{tcp_open_ports}) ;
}

$scan->{protocol} = 'tcp';
$scan->{ports} = [20..110];
$scan->do_it();
$disc->add_interface($_) for ($scan->get_interfaces);

foreach my $h ($scan->get_interfaces) {
    print $h->{ip} . "\n";
    print "    has tcp ports: " . join(',',@{$h->{tcp_open_ports}}) . "\n" if (exists $h->{tcp_open_ports}) ;
}

DESCRIPTION

NetworkInfo::Discovery::Scan is a host/port scanner that is used to find hosts that are too quiet for NetworkInfo::Discovery::Sniff to find. It is a detection module subclassed from NetworkInfo::Discovery::Detect. We can probe tcp or udp ports. There is the ability to set a timeout on the connection so that we don't wait all day for the scan to finish. There is a wait attribute that keeps us from scanning the network too fast and affecting it in a negetive manner. The hosts attribute takes hostnames, ipaddresses, or CIDR-like network/bitmask lists.

METHODS

new

returns a new Scan object, and takes the arguments shown in this example:

    $obj = NetworkInfo::Discovery::Scan->new(
	    hosts     =>    ["hostname", "1.2.3.4", "4.3.2.1/26"],
	    [protocol =>    ("tcp"|"udp")],
	    [timeout  =>    3 ],    #in seconds
	    [wait     =>    100],   #in miliseconds
	    [ports    =>    [80,23,100..300] ],
	);

timeout is the amount of time to wait in seconds before giving up on a connection attempt. wait is how long to wait in miliseconds between each probe. protocol is either tcp or udp -- we will only try to connect to that type of port. hosts is an array ref of hosts to try. The CIDR-like addresses will be expanded out (i.e., 172.16.1.129/24 is really 172.16.1.(0-255)). If this type of addres is used, we do not scan the top and bottom of the range, as this should be the network and broadcast addresses. ports is and arrey ref of numeric ports to scan for each host.

do_it

Runs the scan, builds up hosts out of what we found open, and returns the hostlist.

hosts ([$aref]

Builds up our list of hosts to scan, or returns that list. The aref can contain any of the following: "hostname" "1.2.3.4" "1.2.3.4/26"

The CIDR-like address will be expanded into an address range and all the hosts in that range (minus the top one, and the bottom one) will be added to the host list to be scanned.

scan

Runs a tcp or udp scan against the hosts in our host list. This method uses alarm if you have set the "timeout" attribute, so please keep that in mind and don't use your own alarm while running this.

make_hosts

Builds our hostlist according to how NetworkInfo::Discovery::Detect requires.

try_timeout

This is a wrapper function to wrap our connection attempts in an alarmed eval.

lookup_ip ($ip)

Does a reverse lookup on the IP and returns a list of the names we found.

AVAILABILITY

This module can be found in CPAN at http://www.cpan.org/authors/id/T/TS/TSCANLAN/ or at http://they.gotdns.org:88/~tscanlan/perl/ =head1 AUTHOR

Tom Scanlan <tscanlan@they.gotdns.org>

AUTHOR

Tom Scanlan <tscanlan@they.gotdns.org>

SEE ALSO

NetworkInfo::Discovery::Detect

NetworkInfo::Discovery::Sniff

NetworkInfo::Discovery::Traceroute

BUGS

Please send any bugs to Tom Scanlan <tscanlan@they.gotdns.org>

COPYRIGHT AND LICENCE

Copyright (c) 2002 Thomas P. Scanlan IV. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.