Skip to main content

utmp, wtmp and btmp reader module for Python 3.x

Project description

This project is a binary CPython 3.x module which allows you to interact with the user accounting databases utmp, wtmp, btmp, and lastlog, which keep track of the boot, login and logout events.

It was developed for the fingerd project, which needs to know the last login date of a user, if the user is still logged in, on which line they are connected to the system, and so on. I decided to make my own module to manage these files.

For now, the project is only available on Linux.

For more information, you can consult the docs on pyutmpx.touhey.pro.

Quickstart

A more thorough onboarding guide is available in the documentation; here are some basic instructions.

Install the module by using the following command:

python -m pip install pyutmpx

List all entries in the utmp file:

import pyutmpx

for entry in pyutmpx.utmp:
        print(entry)

Get the last boot time:

import pyutmpx

for entry in pyutmpx.utmp:
        if entry.type != pyutmpx.BOOT_TIME:
                continue
        print(f"Last boot time is {entry.time.isoformat()}")
        exit()

print("No boot time on record.")

Get the last login time and host for a given user:

import pyutmpx

uid = 1000

for entry in pyutmpx.lastlog:
        if entry.uid != uid:
                continue

        print(f"Last login at {entry.time.isoformat()} on {entry.line} "
                f"from {entry.host}")
        exit()

print("No last login.")

What is left to do

  • Expand compatibility to other platforms, such as OpenBSD.

  • Add a list-like interface, with length and index.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyutmpx-0.4.tar.gz (21.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page