Skip to content

Instantly share code, notes, and snippets.

@ryanmaclean
Created April 25, 2016 05:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryanmaclean/cb30238a75138d00b021fe8140f2c79f to your computer and use it in GitHub Desktop.
Save ryanmaclean/cb30238a75138d00b021fe8140f2c79f to your computer and use it in GitHub Desktop.
Mac OSX: Port Scan Your Own Network with Netcat from Homebrew
#!/bin/bash
# Turn on job control to do more than one at a time
set -m
# Check to see if Homebrew is installed, and install it if it is not
command -v brew >/dev/null 2>&1 || { echo >&2 "You will need Homebrew to use this tool, installing now"; /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"; }
# Check to see if `netcat` is installed, install it if it is not
command -v netcat >/dev/null 2>&1 || { echo >&2 "You will also need netcat in order to use this tool, installing it now"; brew install netcat; }
# Prompt the user for the port which we will scan
read -p "Which port would you like to scan? The default is [80]:" PORT
PORT=${PORT:-80}
# Prompt the user for the C-class range we will scan
read -p "For which range? The default is [10.0.1.]:" RANGE
RANGE=${RANGE:-10.0.1.}
# Removed the start and end IP blocks and scan 255 by default
#echo "From what starting IP? The default is 1"
#read -p "From what starting IP? The default is [1]:" STARTIP
#STARTIP=${STARTIP:-1}
for i in {1..254}; do netcat -vnz -w 1 $RANGE$i $PORT; done
# Turn off job control once more
set +m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment