Giter Club home page Giter Club logo

kydns's Introduction

PyPI Version License: MIT

KYDNS

KYDNS (Know Your DNS) is a simple DNS client library written in Python 3. It allows sending DNS queries for A, AAAA, and NS records, easily modify any of the DNS packet fields, and provides an ASCII representation of the DNS packets.
The library is designed to be easy to use and can be used for learning, testing, or other purposes.

Installation

KYDNS uses Python 3 standard libs and has no 3rd party dependencies. Install using pip:

pip install kydns

Or git clone:

git clone https://github.com/eliaonceagain/kydns.git
cd kydns/
pip install .

Usage

Send a DNS query for the A record of google.com and return the response

from kydns import Request

req = Request("google.com")
rsp = req.send(("1.1.1.1", 53))
>>> rsp
                     1
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x382a            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1|  0x0  |0|0|1|1|  0  |  0x0  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0001            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0001            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0000            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0000            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<--
/           google.com          /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0001            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0001            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<--
/           google.com          /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0001            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0001            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                               |
+               80              +
|                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0004            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/                               /
+         172.217.18.14         +
/                               /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<--

Set Query Fields

KYDNS also allows you to easily modify any of the DNS packet fields before sending the query. Here is an example of how to set the DNS request ID:

from kydns import Request

req = Request('google.com')  # or Request('google.com', id=0x1234)
req.header.id = 0x1234  
rsp = req.send(("1.1.1.1", 53))
assert req.header.id == rsp.header.id == 0x1234
>>> req.header
                     1
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x1234            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0|  0x0  |0|0|1|0|  0  |  0x0  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0001            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0000            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0000            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0000            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<--

>>> rsp.header
                     1
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x1234            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1|  0x0  |0|0|1|1|  0  |  0x0  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0001            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0001            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0000            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             0x0000            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<--

License

KYDNS is licensed under the MIT license. See the LICENSE file for more details.

kydns's People

Contributors

eliaonceagain avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.