Skip to content

Instantly share code, notes, and snippets.

@ricardojoserf
Created December 1, 2023 12:39
Show Gist options
  • Save ricardojoserf/e71a67285da1b7371d07fd14d6a8500a to your computer and use it in GitHub Desktop.
Save ricardojoserf/e71a67285da1b7371d07fd14d6a8500a to your computer and use it in GitHub Desktop.
Wrapper for smbmap (Python 2) - Get shares in \\IP\share format
import subprocess
ip_list_file = ""
user = ""
domain = ""
password = ""
ip_list = open(ip_list_file).read().splitlines()
for ip_address in ip_list:
p = subprocess.Popen("smbmap -u "+user+" -p "+password+" -d "+domain+" -H "+ip_address, stdout=subprocess.PIPE, shell=True)
(output, err) = p.communicate()
p_status = p.wait()
try:
ip_ = output[output.find("IP: "):output.find("Disk")]
ip_ = ip_.split(" ")[1].split(":")[0]
for i in output.split("\n"):
if "ACCESS" in i or "READ" in i:
print("\\\\" + ip_ + "\\" + i[:i.find(" ")].replace("\t",""))
except:
if "Authentication error" in output:
#print "Finished " + ip_address
pass
else:
print "Failed with: " + ip_address
print output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment