Skip to content

Commit

Permalink
Merge pull request #58 from hwixley/feature/port-scanner
Browse files Browse the repository at this point in the history
[feature]: Port scanning with nmap
  • Loading branch information
hwixley committed May 28, 2024
2 parents 141e593 + 970079c commit b070b9a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
24 changes: 19 additions & 5 deletions argparse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ num_args=$#
date=$(date)
year="${date:24:29}"

# Load bash classes
# ~~~~~~~~~~~~~~~~ Load classes ~~~~~~~~~~~~~~~~~~~~~~~~
# Load all the bash OOP-style classes to be inherited
# by downstream scripts
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

source $WYX_DIR/src/classes/sys/sys.h
sys sys
source $WYX_DIR/src/classes/wgit/wgit.h
Expand All @@ -16,15 +20,19 @@ wyxd wyxd
source $WYX_DIR/src/classes/lib/lib.h
lib lib

# Load source git data
# ~~~~~~~~~~~~~ Load source git data ~~~~~~~~~~~~~~~~~~~~
# Check if the current directory is a git repository,
# and if so, get the branch and remote URLs across the
# different git hosting services.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
branch=""
if git rev-parse --git-dir > /dev/null 2>&1; then
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
fi
remote=$(git config --get remote.origin.url)
repo_url=$(echo "$remote" | sed 's/[^ \/]*\/\([^ ]*\/[^.]*\).*/\1/')
repo_url=${repo_url%".git"}
repo_url=$(echo "$remote" | sed 's/[^ \/]*\/\([^ ]*\/[^.]*\).*/\1/' | sed 's/\.git//')
git_host=""
#
if [[ $remote == *"github.com"* ]]; then
git_host="github"
repo_url=${repo_url#"git@github.com:"}
Expand All @@ -43,7 +51,11 @@ elif [[ $remote == *"azure.com"* ]]; then
fi



# ~~~~~~~~~~~~~~~~ Parse input ~~~~~~~~~~~~~~~~~~~~~~~~~
# Parse the input into a command object and run it if
# it is valid. If the command is invalid, show an error
# message.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ $num_args -eq 0 ]; then
# No input - show command info
wyxd.command_info
Expand All @@ -57,6 +69,8 @@ else
inputCommand_path="${WYX_DIR}/src/commands/$(inputCommand.path).sh"

if [ -f "${inputCommand_path}" ]; then
# set trap
trap 'inputCommand.unset && echo "trap happening"' EXIT
# Valid command found - run it
source "${inputCommand_path}" "${@:2}"
inputCommand.unset
Expand Down
23 changes: 23 additions & 0 deletions src/commands/port-scan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

host="$1"
port_range="$2"

sys.log.h1 "Port Scanner"
sys.log.hr
sys.log.h2 "This script scans all the open ports on a given host."
sys.log.h2 "Usage: ./port-scan.sh <host> <port-range>"
sys.log.hr
echo ""
if ! wyxd.arggt "1"; then
sys.util.inlineread "Enter the host to scan (defaults to 'localhost'): " host
fi
if ! wyxd.arggt "2"; then
sys.util.inlineread "Enter the port range to scan (defaults to 1-10000): " port_range
fi
host=$(echo "$host" | sed 's/https\?:\/\///')
host=${host:-"localhost"}
port_range=${port_range:-"1-10000"}

sys.log.info "Scanning $host for open ports in the range $port_range with nmap..."
nmap -p "$port_range" "$host"
3 changes: 2 additions & 1 deletion src/data/arg_scripts.csv
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ update-deps,update-deps,"Update the project dependencies",true,,deps
list-deps,list-deps,"List the project dependencies",true,,deps
update-readme,update_readme,"Auto-update the project's readme with the available commands",false,,
update-cache,update_cache,"Auto-update the project's cache with the available commands",false,,
pp,pp,"Pull-Push Git Changes to Current Branch",true,,git
pp,pp,"Pull-Push Git Changes to Current Branch",true,,git
port-scan,port-scan,"Scan for open ports on a host",true,<host?> <port-range?>,nutil

0 comments on commit b070b9a

Please sign in to comment.