#!/bin/bash

#
# $Id: netmap,v 1.2 2008/09/10 10:09:22 raptor Exp $
#
# netmap v0.1 - Simple nmap port scanner helper script
# Copyright (c) 2005 Marco Ivaldi <raptor@0xdeadbeef.info>
#
# NETMAP is a very basic and easily customizable helper
# bash script for use with Fyodor's nmap port scanner,
# meant to avoid the annoying freezes while scanning 
# large IP space blocks with a lot of filtered ports.
#
# Usage example: nohup ./netmap 192.168.0 1 254 &
#

# Some vars
nmap=/usr/bin/nmap

# Command line
network=$1
begin=$2
end=$3

# Local fuctions
function usage() {
	echo ""
	echo "NETMAP v0.1 - Simple nmap port scanner helper script"
	echo "Copyright (c) 2005 Marco Ivaldi <raptor@0xdeadbeef.info>"
	echo ""
	echo "usage  : ./netmap <network> <begin> <end>"
	echo "example: nohup ./netmap 192.168.0 1 254 &"
	echo ""
	exit 1
}

# Input control
if [ -z "$3"  ]; then
	usage
fi

# Perform the port scan (tcp continuous, don't ping, os fingerprint, csv output)
while :
do
	$nmap -p1-65535 -P0 -O -oG $network.$begin.scan $network.$begin

# Go for the next address
	if [ $begin -eq $end ]; then
		break
	else
		begin=$(($begin + 1))
	fi

done

exit 0
