-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnmapscan.sh
More file actions
56 lines (39 loc) · 1.01 KB
/
nmapscan.sh
File metadata and controls
56 lines (39 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
# This is the nmap scan to automate:
# nmap -p- --min-rate 1000 -T4 -sC -sV -v <IP> | tee scan.txt
# Enable strict mode
# Set IFS (safer word splitting)
set -euo pipefail
IFS=$'\n\t'
# Maximum number of parallel jobs (e.g., number of CPU cores)"
MAX_JOBS="$(nproc)"
# Define functions here
usage() {
echo "Usage: $0 <IP>"
echo "Example: $0 10.129.6.135"
exit 1
}
run_scan() {
local ip="$1"
local output="scan.txt"
echo "[*] Starting nmap scan on $ip"
echo "[*] Output file: $output"
nmap -p- --min-rate 1000 -T4 -sC -sV -v "$ip" | tee "$output"
echo "[*] Scan complete. Results saved to $output"
}
# Main function
main() {
# Check if IP argument provided
if [[ $# -lt 1 ]]; then
usage
fi
local target_ip="$1"
# Basic IP format validation
if [[ ! "$target_ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Invalid IP format"
usage
fi
run_scan "$target_ip"
}
# Calling the main function
main "$@"