Sunday, September 10, 2006

An easy to do samba scanner

If you had read the post I made some months ago called "Checking the network with bash" and you liked it, you'll probably like this new one. ;)

I used that same script I wrote to find public samba shared resources, data particulary. Windows by default leave some "open resources" that normally you can access mounting it or with some samba tools. So, the thing is: How do I find public resources in a network? This is what I did:

#!/usr/bin/env bash

function scan(){
PING="$(which ping) -c 1 -W 1"
${PING} ${SUBNET}.${LAST} > /dev/null 2>&1
if [ $? -eq 0 ]; then
SMBRESOURCES=$(smbclient -N -L ${SUBNET}.${LAST} 2>/dev/null | grep Disk | grep -v \\$)
if [ ! -z "${SMBRESOURCES}" ]; then
tput setaf 2
echo -e "Public samba resources in ${SUBNET}.${LAST}:"
tput setaf 1
echo -e "------------------------------------------------------\n"
tput sgr0
tput setaf 3
echo "${SUBNET}.${LAST} is up, but doesn't have public resources"
echo -e "------------------------------------------------------\n"
tput sgr0

if [ -z ${2} ]; then
for((x=1;x<255;x++)); do
${0} ${1} ${x} &
scan ${1} ${2}


Again, and like always... I hope some find it useful


Anonymous said...

this script manages to crash several of my linux box's [ some sort of infinate spawning of tasks, untill all reasources are used.

Anonymous said...

it freeze my linux :(

Nomius said...

The point of the scripts I post here (unless I release a software package), is not that you just plain execute it. But to look at it and understand it.

Both of the comments above makes me think that you just execute it and didn't try to see how it works.

Guys, you need to pass the network that you want to scan, something like: ./script 192.168.1

Anonymous said...

That comment thread made me laugh a long time. "It freeze my linux :("

Thanks, I cribbed your script when I needed to get at a shared drive through an ssh tunnel and now I know what the IP is! Built-in network scanners have made me lazy....