slimta.util.ptrlookup

New in version 0.3.21.

When a client connects to the server, it is useful to know who they claim to be. One such method is looking up the PTR records for the client’s IP address in DNS. If it exists, a PTR record will map an IP address to an arbitrary hostname.

However, it is not usually desired to slow down a client’s request just because their PTR record lookup has not yet finished. This module implements a Greenlet thread that will look up a client’s PTR record will its request is being processed. If the request finishes before the PTR record lookup, the lookup is stopped.

class slimta.util.ptrlookup.PtrLookup(ip)

Bases: gevent._greenlet.Greenlet

Asynchronously looks up the PTR record of an IP address, implemented as a Greenlet thread.

Parameters:ip – The IP address to query.
classmethod from_getpeername(cls, sock)

Creates a PtrLookup object based on the IP address of the socket’s remote address, using getpeername().

Parameters:sock – The socket object to use.
Returns:A tuple containing the new PtrLookup object and the port number from getpeername().
classmethod from_getsockname(cls, sock)

Creates a PtrLookup object based on the IP address of the socket’s local address, using getsockname().

Parameters:sock – The socket object to use.
Returns:A tuple containing the new PtrLookup object and the port number from getsockname().
start()

Starts the PTR lookup thread.

See also

gevent.Greenlet.start()

finish([runtime=None])

Attempts to get the results of the PTR lookup. If the results are not available, None is returned instead.

When this method returns, the Greenlet executing the lookup is killed.

Parameters:runtime (float) – If this many seconds have not passed since the lookup started, the method call blocks the remaining time. For example, if 3.5 seconds have elapsed since calling start() and you pass in 5.0, this method will wait at most 1.5 seconds for the results to come in.
Returns:The PTR lookup results (a hostname string) or None.