Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #------------------------------------------
- # scan smb shares in windows network
- # requires: nmap, smbclient, nmblookup
- #------------------------------------------
- # show $ shares
- showadm=0
- fname="$HOME/shares.txt"
- iprange="192.168.15,27,19.1-224"
- ips=''
- t=''
- count=0
- scount=0
- /usr/bin/notify-send -u normal -t 2000 -i gnome-network-preferences -c network "SMB shares scanning" "Ping..."
- echo "writing shares to: $fname"
- echo "Scanned at `date`" > $fname
- echo "For exploring some machine:" >> $fname
- echo " smb://ip-address (e.g.: smb://192.168.27.1/)" >> $fname
- echo "" >> $fname
- ips=`nmap -n -p 139 "$iprange" -oG - 2>/dev/null | grep open | awk '{ printf "%s ", $2 }'`
- for i in ${ips[@]}
- do
- t=`/usr/bin/nmblookup -A $i 2>/dev/null | grep "<00> - " | awk '{ printf "%s", $1 }'`
- /usr/bin/notify-send -u normal -t 800 -i gnome-network-preferences -c network "SMB shares scanning" "Scanning $t ($i)"
- u=`smbclient -N -L //$t/ -I $i 2>/dev/null | grep '^[^Domain]' | awk -v SHOWADM=$showadm '
- BEGIN { isprint=0; preprint=0 }
- {
- if ($1 == "Server" || $1 == "Error") isprint=0;
- curprint=1;
- if (SHOWADM == 0 && $1 ~ /[\$]$/) curprint=0;
- if (isprint == 1 && curprint == 1) {
- if ( $(NF-1) == "Disk" || $(NF) == "Disk") {
- de=0;
- if ( $(NF-1) == "Disk") de=1;
- for (i=1; i < NF-de; i++) { printf " %s", $(i) }
- printf ";";
- }
- }
- if ($1 == "Sharename") preprint=1;
- if ($1 == "---------" && preprint == 1) { isprint=1; preprint=0 }
- }
- END { printf "\n" }'`
- if [ x"$u" != x ]
- then
- count=$(echo "$count+1" | bc)
- echo $i $t >> $fname
- echo " $u" >> $fname
- echo "" >> $fname
- fi
- scount=$(echo "$scount+1" | bc)
- done
- /usr/bin/notify-send -u normal -t 5000 -i gnome-network-preferences -c network "SMB shares scanning" "$scount hosts scanned. $count contain some shares"
- /usr/bin/gedit $fname &
Advertisement
Add Comment
Please, Sign In to add comment