password fetch using python
import pwd
import operator
# Load all of the user data, sorted by username
all_user_data = pwd.getpwall()
interesting_users = sorted((u
for u in all_user_data
if not u.pw_name.startswith('_')),
key=operator.attrgetter('pw_name'))
# Find the longest lengths for a few fields
username_length = max(len(u.pw_name) for u in interesting_users) + 1
home_length = max(len(u.pw_dir) for u in interesting_users) + 1
# Print report headers
fmt = '%-*s %4s %-*s %s'
print fmt % (username_length, 'User',
'UID',
home_length, 'Home Dir',
'Description')
print '-' * username_length, '----', '-' * home_length, '-' * 30
# Print the data
for u in interesting_users:
print fmt % (username_length, u.pw_name,
u.pw_uid,
home_length, u.pw_dir,
开发者_JAVA技巧 u.pw_gecos)
the above program fetch password from linux password file, i want to create the program which shows linux kernel file which maintain logs of user login. how to get into the kernel please help.......
Look at wtmp and utmp. There are APIs - check man wtmp
精彩评论