.. link: http://dgplug.org/summertraining/2013/posts/m0rin09ma3-user_finder_v2-20130717-154006.html .. description: .. tags: .. date: 2013/07/17 15:40:07 .. title: m0rin09ma3 user_finder_v2 20130717-154006 .. slug: m0rin09ma3-user_finder_v2-20130717-154006 user_finder ============ 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`_. .. _source code: https://github.com/m0rin09ma3/python-summer-training-2013/blob/master/user_finder/user_finder.py Sample output: --------------- .. code-block:: ['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. .. code-block:: python 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)]