-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdvce-scan
More file actions
72 lines (63 loc) · 3.04 KB
/
dvce-scan
File metadata and controls
72 lines (63 loc) · 3.04 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
clear
location=$(pwd)
cd /
# Make Configs
if [[ "$(uname -o 2>/dev/null)" == "Android" ]]; then
continue
fi
# Extracting IP range start from eth0
prefix=$(ip addr show eth0 | grep -oP 'inet \K([0-9]{1,3}\.){3}' | tr -d ' ')
if [ -z "$prefix" ]; then
echo "Error: Could not determine IP address range. Exiting."
exit 1
fi
# Function to get the maximum length of an array of strings
max_length() {
local max=0
for i in "$@"; do
local len=${#i}
if [ "$len" -gt "$max" ]; then
max="$len"
fi
done
echo "$max"
}
# Array to store device information
declare -a devices=()
# Scan for Devices IP & DNSs using arp-scan
mapfile -t scan_results < <(sudo arp-scan --localnet | grep -E "([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})" | awk '{print $1,$2}')
# Process the scan results
for line in "${scan_results[@]}"; do
ip=$(echo "$line" | awk '{print $1}')
mac=$(echo "$line" | awk '{print $2}')
dns_name=$(host "$ip" | awk '/domain name pointer/{print $5}')
if [ -z "$dns_name" ]; then
dns_name="Unknown"
fi
devices+=("$dns_name" "$ip ($mac)")
done
# Calculate field widths
max_dns_length=$(max_length "${devices[@]::${#devices[@]}/2}")
max_ip_length=$(max_length "${devices[@]:${#devices[@]}/2}")
# Print the formatted output
clear
echo " ┌────────────────────────────────────────┐ "
echo " │ |D|V|C|E|-|S|C|A|N| │ "
echo " └────────────────────────────────────────┘ "
echo " .:: DEVELOPED BY PENTAGONE GROUP ::. "
echo "────────────────────────────────────────────"
echo " └─[ PREFIX ] ➤ $prefix{1-255} "
echo "────────────────────────────────────────────"
echo
echo -e "┌──────────────────────────────────┬──────────────────────────────────┐"
echo -e "│ DEVICE DNS NAMES │ DEVICES IP & MAC ADDRESSES │"
echo -e "└──────────────────────────────────┴──────────────────────────────────┘"
for ((i = 0; i < ${#devices[@]}; i += 2)); do
printf "│ %-*s │ %-*s │\n" "$((max_dns_length + 2))" "${devices[$i]}" "$((max_ip_length + 2))" "${devices[$((i + 1))]}"
done
echo
echo "───────────────────────────────────────────"
echo " Done. "
echo "───────────────────────────────────────────"
cd $location