Lab 2.1 Port Scanning 1 - zacharylongo/Tech-Journals GitHub Wiki
- The main goals of the assignment were to create enhanced Nmap scanning scripts (and analyze the outputs in WireShark).
#!/bin/bash
hostfile=$1
portfile=$2
# Check if the hostfile and portfile are provided
if [ -z "$hostfile" ] || [ -z "$portfile" ]; then
echo "Usage: $0 <hostfile> <portfile>"
exit 1
fi
# Check if the hostfile exists and is readable
if [ ! -r "$hostfile" ]; then
echo "Error: Host file '$hostfile' does not exist or is not readable."
exit 1
fi
# Check if the portfile exists and is readable
if [ ! -r "$portfile" ]; then
echo "Error: Port file '$portfile' does not exist or is not readable."
exit 1
fi
# Check if 'timeout' command is available
if ! command -v timeout &>/dev/null; then
echo "Error: 'timeout' command is not available. Please install it."
exit 1
fi
echo "host,port"
for host in $(cat "$hostfile"); do
for port in $(cat "$portfile"); do
timeout .1 bash -c "echo >/dev/tcp/$host/$port" 2>/dev/null &&
echo "$host,$port"
done
done
- The above script is based off of the one presented in the lab with extra functions that check if the hostfile/portfile exist and whether
timeoutis installed or not.
-
Overall I had little issue with this lab outside of
10.0.5.31being down. (which impacted my results in two deliverables) -
A key takeaway is that
/dev/tcp/thehostip/thetcpportis not an actual file/directory and is a placeholder for bash to be able to interact with network connections.