#!/bin/bash

#
# $Id: fnetmap,v 1.1.1.1 2007/04/18 14:37:17 raptor Exp $
#
# fnetmap v0.1 - Simple nmap port scanner helper script
# Copyright (c) 2006 Marco Ivaldi <raptor@0xdeadbeef.info>
#
# FNETMAP 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.
#
# See also: http://www.0xdeadbeef.info/code/netmap
#
# Usage example: nohup ./netmap hosts.txt &
#

# Some vars
nmap=/usr/bin/nmap

# Command line
filename=$1

# Local fuctions
function usage() {
	echo ""
	echo "FNETMAP v0.1 - Simple nmap port scanner helper script"
	echo "Copyright (c) 2006 Marco Ivaldi <raptor@0xdeadbeef.info>"
	echo ""
	echo "usage  : ./netmap <filename>"
	echo "example: nohup ./netmap hosts.txt &"
	echo ""
	exit 1
}

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

if [ "`cat $filename 2>/dev/null`" = "" ]; then
	echo "err: corrupted hosts file?"
	exit 1
fi

# Perform the port scan (tcp continuous, don't ping, os fingerprint, csv output)
for current in `cat $filename`
do
	$nmap -p1-65535 -P0 -O -oG $current.scan $current
done

exit 0
