Skip to main content

Simple ident protocol parser for Python AsyncIO

Project description

AIO Ident

Simple ident protocol (RFC 1413) parser for Python AsyncIO.

Install

It's just as simple as

pip install aioident

Doesn't require anything external as it only relies on standard modules.

Usage

It can connect to a host running an ident daemon.

import asyncio
import aioident

async def main():
    res = await aioident.connect("someone.sometld.com", 5912, 6667) # Assumes you are running at port 6667, and the remote host originates from port 5912 ( don't ask me, it's just some TCP sorcery ;) )
    # res = await aioident.connect("someone.sometld.com", 5912, 6667, 1113) # You can also use a different ident port if needed
    if res.ok and res.type == "UNIX":
        print(f"It works! Username: {res.username}")
    else:
        print(f"It doesn't work. Response: {res.type}")

asyncio.run(main())
# It works! Username: swee

It can also parse an ident response that has been already made.

import aioident

def test(text):
    try:
        res = aioident.parse(text)
        if res.ok:
            print(f"Is an ident response. Username is {res.username}")
        else:
            print(f"Is an ident response, but it failed. Error is {res.type}")
    except:
        print("That isn't an ident response.")

test("5912, 6667 : USERID : UNIX : swee") # Spaces are optional (not used in some identd software)
# Is an ident response. Username is swee

test("5912, 6667 : ERROR : NO-USER")
# Is an ident response, but it failed. Error is NO-USER

test("foo bar baz")
# That isn't an ident response.

Ident class

A simple class for parsing specific parts of the ident response (like checking statuses in requests)

This class is always returned with both aioident.connect and aioident.parse however it can also be built manually.

myident = aioident.Ident(5912, 6667, "USERID", "UNIX : swee") # straightforward building

myident.serverport # 5912

myident.clientport # 6667

# ^ It's easy to be confused with those two, but the "server" in this case is the identd listener.

myident.status # "USERID"

myident.data # "UNIX : swee"

# ^ Those four are the values already put in when building

myident.data_split # ["UNIX", "swee"], just splits the colons and automatically strips the spaces for each

myident.ok # True, Returns False if the status is ERROR and not USERID

myident.type # "UNIX", The type of username (usually UNIX) or the reason for error

myident.username # "swee", The username if successful and the type is UNIX. if both aren't true, then it will return None

myident.stringify # "5912, 6667 : USERID : UNIX : swee", Turns that class back into a string for a regular ident response

Example 2, with an error

myident = aioident.Ident(5912, 6667, "ERROR", "NO-USER") # still straightforward

myident.serverport # 5912

myident.clientport # 6667

myident.status # "ERROR"

myident.data # "NO-USER"

myident.data_split # ["NO-USER"]

myident.ok # False

myident.type # "NO-USER"

myident.username # None

myident.stringify # "5912, 6667 : ERROR : NO-USER"

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

aioident-2.0.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aioident-2.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file aioident-2.0.0.tar.gz.

File metadata

  • Download URL: aioident-2.0.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.24

File hashes

Hashes for aioident-2.0.0.tar.gz
Algorithm Hash digest
SHA256 2642bfe13e880f112daf5c0e31d890db0b7b05bb27b3d4019f7d623b62601771
MD5 c654ff6a2eb00b4aeef874b95f8a8fd0
BLAKE2b-256 2187022b38ad8d8766e65ec7379973d46786440a5f9736614afede9ba5cec96e

See more details on using hashes here.

File details

Details for the file aioident-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: aioident-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.24

File hashes

Hashes for aioident-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70894996a4dfb5793ff5d5a699976b63d8ef9f6a8854939e479653887dd1e6b6
MD5 857ff0d314b4e32d2dedf04cf1361638
BLAKE2b-256 1574206d3f2328d22367d3c4ce6edabd7042e3b74ea06d9d5b11fc38fe69102a

See more details on using hashes here.

Supported by

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