Created
December 1, 2023 12:39
-
-
Save ricardojoserf/e71a67285da1b7371d07fd14d6a8500a to your computer and use it in GitHub Desktop.
Wrapper for smbmap (Python 2) - Get shares in \\IP\share format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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