-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from hwixley/feature/port-scanner
[feature]: Port scanning with nmap
- Loading branch information
Showing
3 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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#"[email protected]:"} | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters