-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractPorts
More file actions
37 lines (32 loc) · 1.07 KB
/
extractPorts
File metadata and controls
37 lines (32 loc) · 1.07 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
#!/bin/bash
# Used:
# nmap -p- --open -T5 -v -n ip -oG allPorts
# Extract nmap information
# Run as:
# extractPorts allPorts
function extractPorts(){
# say how to usage
if [ -z "$1" ]; then
echo "Usage: extractPorts <filename>"
return 1
fi
# Say file not found
if [ ! -f "$1" ]; then
echo "File $1 not found"
return 1
fi
#if this not found correctly, you can delete it, from "if" to "fi".
if ! grep -qE '^[^#].*/open/' "$1"; then
echo "Format Invalid: Use -oG <file>, in nmap for a correct format."
return 1
fi
ports="$(cat $1 | grep -oP '\d{1,5}/open' | awk '{print $1}' FS='/' | xargs | tr ' ' ',')";
ip_address="$(cat $1 | grep -oP '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' | sort -u | head -n 1)"
echo -e "\n[*] Extracting information...\n" > extractPorts.tmp
echo -e "\t[*] IP Address: $ip_address" >> extractPorts.tmp
echo -e "\t[*] Open ports: $ports\n" >> extractPorts.tmp
echo $ports | tr -d '\n' | xclip -selection clipboard
echo -e "[*] Ports copied to clipboard\n" >> extractPorts.tmp
cat extractPorts.tmp; rm extractPorts.tmp
}
extractPorts "$1"