blob: c0de47d70c4b9aaa15a71d31f758e77b20c5adef (
plain)
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
|
#!/bin/sh
# props to https://andreafortuna.org/2016/08/08/simple-smb-scanner-with-a-single-line-of-shell/
# plus some tweaks from me
dmenu=cdmenu
subnet=$1
if [ -z $subnet ]; then
echo "No subnet specified, using local..."
IP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
subnet="$(echo $IP | cut -d. -f1-3).*"
echo "Scanning subnet $subnet"
fi
scan() {
nmap $1 -p 445 --open -oG - | grep "Host:" | cut -d " " -f 2 | uniq | xargs -I '{}' sh -c 'echo "Scan {}";echo "---------";smbclient -L//{} -N'
}
#scanresult=$(scan)
scanresult="""Scan 192.168.70.1
---------
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
public Disk
IPC$ IPC IPC Service (Samba 4.13.13-Debian)
SMB1 disabled -- no workgroup available
Scan 192.168.70.3
---------
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
IPC$ IPC IPC Service (Samba 4.13.14-Debian)
SMB1 disabled -- no workgroup available"""
printf "$scanresult\n"
IPs=$(echo "$scanresult" | grep Scan | cut -d' ' -f2-)
printf "Server IPs:\n$IPs\n"
IP=$(printf "$IPs" | $dmenu -l 64)
echo "Selected $IP"
shares="""$(scan $IP)"""
printf "Shares:\n$shares\n"
# cut off header from smbclient with tail and warning about SMB1 with head
shares=$(printf "$shares" | tail -n +6 | head -n -1)
printf "Filtered shares:\n$shares\n"
share=$(printf "$shares" | $dmenu -l 64 -p "Select share to mount" | tr -s " ")
printf "$share"
share=$(echo $share | cut -d' ' -f 1)
echo $share
user=$(: | $dmenu -i -p "Input user name:")
mount -t cifs -o user="$user" //"$IP"/"$share" <MOUNT POINT>
|