SMBClient from multiple ip

336 views Asked by At

I would like to make a bash script where I read a list of IP addresses and run the following command:

smbclient \\\\ $ ip \\ ipc $ -U ". \ User" --pw-nt-hash

which does an exit and try with another IP, regardless of that it throws a message if the connection was successful, it does not execute with the IPs that are inside the list, it only tries with the first one in the list.

#/bin/bash 

IPLIST="ip"

for ip in $(cat ip)
do
   smbclient \\\\$ip\\C$ -U ".\user" --pw-nt-hash "user"
   exit
done 
2

There are 2 answers

0
Armali On

If you don't want the script to exit after the first smbclient, drop the exit command.

smbclient \ $ ip \ ipc $ -U ". \ User" --pw-nt-hash, which does an exit

This exit is not done by smbclient, but rather by the script; therefore it ends.

0
tripleee On

You seem to assume that the exit gets passed as input to smbclient, but that's not how this works. You run smbclient and when it finishes, your script continues, and executes the exit. See Pass commands as input to another command (su, ssh, sh, etc) for a fuller discussion.

Also, don't read lines with for.

#/bin/bash 

while read -r ip; do
   smbclient \\\\$ip\\C$ -U ".\user" --pw-nt-hash "user" <<<exit
done <ip