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 asyncio
import aioident

async def main(text):
    try:
        res = await 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 ValueError:
        print("That isn't an ident response.")

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

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

asyncio.run(main("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-1.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-1.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aioident-1.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-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c7d2c9c40267a5a9c178adaf77977406762f447e1b6b73db998ea450ba9e3284
MD5 f520dc235fd1111b49ca33e030c3d567
BLAKE2b-256 b2e3ad7d937e1d7d5111d45e130713b39ba82a942afc7e7af3c2e6b65818f14b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aioident-1.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-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0073a4c40deb34f636fffae4d49912a2fff4242ef15b7587913a36bf606fccc
MD5 e01a76be189ccbbd32a8f86f023a390a
BLAKE2b-256 ca54416b9f37cd4e52a69deeb85f516c365e3653836487eff06d04df23ea96a0

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