File: genlist

package info (click to toggle)
pbnj 2.04-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 640 kB
  • ctags: 309
  • sloc: perl: 4,838; xml: 748; sh: 109; makefile: 37
file content (127 lines) | stat: -rwxr-xr-x 3,385 bytes parent folder | download | duplicates (2)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/perl
#
# Copyright (C) 2005-2006 Joshua D. Abraham (jabra@ccs.neu.edu)
#
# This program is released under the terms of the GNU General Public License
# (GPL), which is distributed with this software in the file "COPYING".
# The GPL specifies the terms under which users may copy and use this software.
#
# PBNJ 2.0
# (P)orts (B)anners N' (J)unk
#
# Author:   Joshua D. Abraham
# Date:     March 15, 2006
# Updated:  November 15, 2006
# Version:  2.04
# 
#
# Genlist - ping scanner
#

use strict;
use warnings;

use FileHandle;
use Nmap::Parser;
use Getopt::Long;
use File::Which;

use vars qw( $PROG );
( $PROG = $0 ) =~ s/^.*[\/\\]//;    # Truncate calling path from the prog name

my $AUTH    = 'Joshua D. Abraham';  # author
my $VERSION = '2.04';               # version

my $np = new Nmap::Parser;          # parser object

my $list;                           # output list of live hosts;
my @output_files;
my $ipfound;
my $type      = 'help';
my $outputdir = '.';                # output database directory
my $nmapPath  = which('nmap');      # nmap path
my $args      = "-sP";
my $interface = "";                 # default interface to perform scan
my @ipRange;
my %options;                        # getopts hash
##############################################################################
# scan ->
# performs a ping scan and prints the list of machines that are up
# side effects: exits program
##############################################################################
sub scan {
    $np->parsescan( $nmapPath, $args, @ipRange );
    for my $host ( $np->get_ips('up') ) {
        print "$host\n";
    }
    exit;
}
##############################################################################
#
# help ->
# display help information
# side effect:  exits program
#
##############################################################################
sub help {
    print "Usage: $PROG [Input Type] [General Options]
Input Type:
   -s  --scan <target>      Ping Target Range ex: 10.0.0.\\*

Scan Options:
   -n  --nmap <path>        Path to Nmap executable 
       --inter <interface>  Perform Nmap Scan using non default interface

General Options:
   -v  --version            Display version
   -h  --help               Display this information

Send Comments to Joshua D. Abraham ( jabra\@ccs.neu.edu )\n";
    exit;
}

sub print_version {
    print "$PROG version $VERSION by $AUTH\n";
    exit;
}

##############################################################################

GetOptions(
    \%options,
    'scan|s=s', 'nmap|n=s', 'inter=s',
    'help|h'    => sub { help(); },
    'version|v' => sub { print_version(); },
    )
    or exit 1;

if ( $options{'nmap'} ) {
    if ( -X $options{'nmap'} ) {
        $nmapPath = $options{'nmap'};
    }
    else {
        print $options{'nmap'} . " isn't executable using $nmapPath\n";
    }
}
if ( $options{'scan'} ) {
    my $ipRange;
    if ( $options{'scan'}
        =~ /(\d{1,3})\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(0\/\d{1,2}|\d{1,3}|\*|'*')/
        )
    {
        $ipRange = $options{'scan'};
        $type    = 'scan';
    }
    else {
        print "scan is $options{'scan'}";
    }
    push( @ipRange, $ipRange );
}
if ( $options{'inter'} ) {
    $interface = "-e " . $options{'interface'} . " ";
    $args      = $args . $interface;
}

# make sure something is passed
help() if ( $type ne 'scan' );
scan();