python - 使用python获取密码

标签 python linux passwords

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, 
                 u.pw_gecos)

上面的程序从 linux 密码文件中获取密码, 我想创建一个程序来显示维护用户登录日志的 linux 内核文件。 如何进入内核请帮忙.......

最佳答案

看看 wtmp 和 utmp。有 API - 检查 man wtmp

关于python - 使用python获取密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3873128/

相关文章:

python - 使用 scikit-learn 的线性判别分析类时 lapack 函数的 SVD 计算错误

python - tkinter ttk TreeView 彩色行

python - Visual C++ Redistributable 2015 已删除且无法重新安装

java - 在 Eclipse 中使用数据库集成进行用户界面 JUnit 测试

python - 错误 : [Errno 10053]

c - 避免 IDT Hook 中的页面错误

linux - 当我关闭腻子窗口时,glassfish 停止

c - 为什么 seccomp 进程总是被杀死?

linux - 提供 root 访问权限,但不提供 DB 访问权限

java - 正确输入下一个 Activity 的文本