Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # +-----------------------------------------------------------------------------------------+
- # | nmap host check - scans subnet on ip's |
- # | |
- # | |
- # | |
- # | Augustus 2011 flip hess [email protected] |
- # +-----------------------------------------------------------------------------------------+
- # Global variables:
- PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'
- SCRIPT_PATH="${0}"
- ARGS="${#}"
- # Functions:
- # exit function
- function die()
- {
- echo "${1}"
- exit 1
- }
- # Shows usage function.
- function fShowUsage()
- {
- echo "Usage: ${SCRIPT_PATH}"
- return 0
- }
- # check for.......
- function fCheck()
- {
- # script depends on:
- [ -x $(which nmap) ] || die "This script depends on nmap"
- # user must be root:
- [ $(whoami) = root ] || die "User must be root!"
- # check for arguments:
- [ ${ARGS} = 0 ] || { fShowUsage; exit 1; }
- echo ""
- return 0
- }
- # The main function.
- function fMain()
- {
- # determine subnet
- NET="$( ifconfig | grep 'Bcast:' | cut -d ":" -f 2 | cut -d "." -f 1,2,3 )"
- # ping all subnet hosts /24
- HOSTS="$( nmap ${NET}.0/24 -sP | grep 'report' | sed -e "s/.*${NET}.//" -e 's/)//g' )"
- # for loopje met mooie resultaatjes:
- for HOST in ${HOSTS}
- do
- NAME="$( host ${NET}.${HOST} | grep 'domain' | awk '{ print $NF }' | cut -d '.' -f 1,2,3 )"
- echo "${NET}.${HOST}.:${NAME}"
- ONLINE[`expr ${#ONLINE[@]} + 1`]=${HOST}
- done
- echo
- echo "Computers online: ${#ONLINE[*]}"
- return 0
- }
- # check environment:
- fCheck
- # Start the program:
- fMain "${@}"
- # Exit with previous return code:
- exit "${?}"
Advertisement
Add Comment
Please, Sign In to add comment