m0rin09ma3 user_finder_v2 20130717-154006


Posted:

This program will read /etc/passwd info and output user who can do aproper login.

$ python user_finder.py

A link to the source code.

Sample output:

['root', 'm0rin09ma3']

Explanation

In the main function, use regular expression to filter out users who has /bin/false or /sbin/nologin default shell. Then output the rest of users.

all_user = pwd.getpwall()
#print all_user

notvalid = re.compile('.*/(nologin|false)')
daemon = re.compile('.*daemon', re.IGNORECASE)
print [user.pw_name for user in all_user if \
        (not notvalid.match(user.pw_shell)) and \
        (not daemon.match(user.pw_gecos))]
#print [user.pw_name for user in all_user if not notvalid.match(user.pw_    shell)]
#print [user.pw_name for user in all_user if not daemon.match(user.pw_ge    cos)]
Contents © 2013 dgplug - Powered by Nikola
Share
UA-42392315-1