daily pastebin goal
23%
SHARE
TWEET

portscan.sh

a guest Aug 19th, 2018 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # Script to run nmap scan of selected Class C address block on selected port(s)
  3. # and clean-up results to return list of ip addresses with open port(s)
  4. # based on Null Byte script by OTW and modifications by appledash48
  5. # this version by jr_bob_dobbs 2018-08-18
  6.  
  7. # set variable for working directory where results will be saved
  8. SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
  9.  
  10. # boilerplate function for GOTO functionality (jumpto)
  11. function jumpto
  12. {
  13.    label=$1
  14.    cmd=$(sed -n "/$label:/{:a;n;p;ba};" $0 | grep -v ':$')
  15.    eval "$cmd"
  16.    exit
  17. }
  18. start=${1:-"start"}
  19.  
  20. jumpto $start
  21.  
  22. start:
  23. #script starts here
  24. echo
  25. echo "Enter IP address block to scan (/24)"
  26. echo "Example: google.com is 74.125.225.0"
  27. echo
  28. read IP
  29. echo
  30. echo "Enter port to be scanned"
  31. echo "Example: 5505"
  32. echo "Example2: To scan multiple ports, format it like this: 5505-6000"
  33. echo
  34. read PORT
  35. echo
  36. read -r -p "Scanning "$IP" subnet for port "$PORT"; Is this correct? [y/N]" response
  37. response=${response,,}
  38. if [[ $response =~ ^(yes|y)$ ]]
  39. then
  40.    echo
  41.    echo "Scanning "$IP" on port "$PORT" now ..."
  42.    echo
  43.    nmap -sT $IP/24 -p $PORT -oG scanresults
  44.    cat scanresults |grep open > portsopen
  45.    cat portsopen |cut -f2 -d ":" |cut -f1 -d"(" > scanresults-$IP-port-$PORT
  46.    #clean-up temp results files and then display final results
  47.    echo
  48.    echo "Cleaning up temp files ...."
  49.    rm -f scanresults
  50.    rm -f portsopen
  51.    echo
  52.    echo "Showing list of vulnerable ip addresses now ..."
  53.    echo
  54.    cat scanresults-$IP-port-$PORT
  55.    echo
  56.    echo "Results have been saved to "$SCRIPT_DIR"/scanresults-"$IP"-port-"$PORT""
  57.    echo
  58.    echo
  59. else
  60.     jumpto $start
  61. fi #Cx2H
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top