[Twisted-Python] How to get the client ip when it ask a resolution with twisted.names

Adi Roiban adi at roiban.ro
Sat May 1 03:18:08 MDT 2021


Hi

On Sat, 1 May 2021 at 07:43, contact at benoit-laviale.fr <
contact at benoit-laviale.fr> wrote:

> Dear all,
>
> I am working on twisted names since some days to make kind of filtering
> system (with domains blacklists).
> So I made my own resolver that can reply defer.fail(error.DomainError())
> to send the query to the next resolver (and in this case, it will be
> resolve) or defer.fail(dns.AuthoritativeDomainError(query.name.name)) to
> reply NXDOMAIN that can "block" the domain to the final client.
>
> That part is working well.
>
> Next, i would like to "block" the resolution regarding the device (Mac
> address/IP/???).
>
> I would like something like that :
>
> if self.query.meta.client.ip == b"192.168.0.5" or
> self.query.meta.client.mac == "XX:YY:ZZ:....":
>          self.do_something()
>
> My use case is that device of Kelly, (Kelly is a teenager of 12 years)
> cant use youtube.com at all, but other devices are allowed to get the
> resolution.
> How can I get the IP/Name/mac (an identifier) of the device that's
> querying my custom dns?
> I read something about datagrams, but in my case i think i must get this
> information in my resolver...
>
> Thx and cheers.
>

I think you are using DNS over UDP... so to understand how UDP works with
Twisted you can check this page
https://twistedmatrix.com/documents/current/core/howto/udp.html

 I have never used Twisted names so I am just trying to help based on my
general knowledge of Twisted design
... but I think the entry point is here

https://github.com/twisted/twisted/blob/63649469c1fe46d8a713e8034239ac3cc0498ea7/src/twisted/names/dns.py#L3242

then it goes to here

https://github.com/twisted/twisted/blob/63649469c1fe46d8a713e8034239ac3cc0498ea7/src/twisted/names/server.py#L538

and then in handleQuery where I see that the  query is done without the
`address`...but the address is available again in
`gotResolverResponse`.. so maybe that help

-------

Hope it helps

Cheers

-- 
Adi Roiban
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20210501/8fc7b573/attachment-0001.htm>


More information about the Twisted-Python mailing list