- Saved searches
- Use saved searches to filter your results more quickly
- License
- Douile/pydns
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- dnserver 0.4.0
- Навигация
- Ссылки проекта
- Статистика
- Метаданные
- Сопровождающие
- Классификаторы
- Описание проекта
- dnserver
- Installation from PyPI
- Usage with Python
- andreif / Simple DNS server (UDP and TCP) in Python using dnslib.py
- Saved searches
- Use saved searches to filter your results more quickly
- akapila011/DNS-Server
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A fully python dns server
License
Douile/pydns
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
A fully python 3 implementation of a DNS server
- At the moment the only records supported are IPV4 A records (however the main codebase is there to support others)
- TTL will be set to 0 as not to corrupt cache with bad records, in the future this can be changed
- Sometimes must run as root/admin to bind port 53 (any port < 1000)
- This «server» only supports UDP based DNS requests (ATM), and will not make actual DNS queries to retrieve actual results: the intention of this «server» is to send fake addresses back to clients that send requests to it based on the contents of the given hosts.txt file
You can setup hosts in a hosts.txt file in the format
test.com 127.0.0.1 google.com 216.58.212.110
Must use python 3
usage: main.py [-h] [-f HOSTS] [-a ADDRESS] [-p PORT] [-d] A python DNS server optional arguments: -h, --help show this help message and exit -f HOSTS, --hosts HOSTS The file to load hosts from -a ADDRESS, --address ADDRESS Address to bind -p PORT, --port PORT Port to bind -d, --debug Print debug messages
- Open nslookup
- Enter SET debug
- Optional enter SET TYPE=ALL
- Enter server 127.0.0.1 or whatever IP you bound to (must be using port 53)
- Query a domain name you have in your hosts.txt configuration
dnserver 0.4.0
Simple DNS server written in python for use in development and testing.
Навигация
Ссылки проекта
Статистика
Метаданные
Лицензия: MIT License
Требует: Python >=3.7
Сопровождающие
Классификаторы
- Development Status
- 4 — Beta
- Console
- Developers
- Information Technology
- System Administrators
- OSI Approved :: MIT License
- POSIX :: Linux
- Unix
- Python
- Python :: 3
- Python :: 3 :: Only
- Python :: 3.7
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Internet
- Internet :: Name Service (DNS)
- Software Development :: Libraries :: Python Modules
- Software Development :: Testing
- Software Development :: Testing :: Mocking
- System :: Systems Administration
Описание проекта
dnserver
Simple DNS server written in python for use in development and testing.
The DNS serves its own records, if none are found it proxies the request to an upstream DNS server eg. CloudFlare at 1.1.1.1 .
You can set up records you want to serve with a custom zones.toml file, see example_zones.toml an example.
Installation from PyPI
(or python -m dnserver —help )
For example, to serve a file called my_zones.toml file on port 5053 , run:
Usage with Python
Or with a custom zone file:
(assuming you have your zone records at ./zones.toml , TCP isn’t required to use dig , hence why it’s omitted in this case.)
You can then test (either of the above) with
~ ➤ dig @localhost -p You can see that the first query took 2ms and returned results from example_zones.toml , the second query took 39ms as dnserver didn't have any records for the domain so had to proxy the query to the upstream DNS server.
andreif / Simple DNS server (UDP and TCP) in Python using dnslib.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
# coding=utf-8 «»» LICENSE http://www.apache.org/licenses/LICENSE-2.0 «»» import datetime import sys import time import threading import traceback import SocketServer from dnslib import * class DomainName ( str ): def __getattr__ ( self , item ): return DomainName ( item + ‘.’ + self ) D = DomainName ( ‘example.com’ ) IP = ‘127.0.0.1’ TTL = 60 * 5 PORT = 5053 soa_record = SOA ( mname = D . ns1 , # primary name server rname = D . andrei , # email of the domain administrator times = ( 201307231 , # serial number 60 * 60 * 1 , # refresh 60 * 60 * 3 , # retry 60 * 60 * 24 , # expire 60 * 60 * 1 , # minimum ) ) ns_records = [ NS ( D . ns1 ), NS ( D . ns2 )] records = D : [ A ( IP ), AAAA (( 0 ,) * 16 ), MX ( D . mail ), soa_record ] + ns_records , D . ns1 : [ A ( IP )], # MX and NS records must never point to a CNAME alias (RFC 2181 section 10.3) D . ns2 : [ A ( IP )], D . mail : [ A ( IP )], D . andrei : [ CNAME ( D )], > def dns_response ( data ): request = DNSRecord . parse ( data ) print request reply = DNSRecord ( DNSHeader ( id = request . header . id , qr = 1 , aa = 1 , ra = 1 ), q = request . q ) qname = request . q . qname qn = str ( qname ) qtype = request . q . qtype qt = QTYPE [ qtype ] if qn == D or qn . endswith ( ‘.’ + D ): for name , rrs in records . iteritems (): if name == qn : for rdata in rrs : rqt = rdata . __class__ . __name__ if qt in [ ‘*’ , rqt ]: reply . add_answer ( RR ( rname = qname , rtype = QTYPE [ rqt ], rclass = 1 , ttl = TTL , rdata = rdata )) for rdata in ns_records : reply . add_ns ( RR ( rname = D , rtype = QTYPE . NS , rclass = 1 , ttl = TTL , rdata = rdata )) reply . add_ns ( RR ( rname = D , rtype = QTYPE . SOA , rclass = 1 , ttl = TTL , rdata = soa_record )) print «—- Reply: \n » , reply return reply . pack () class BaseRequestHandler ( SocketServer . BaseRequestHandler ): def get_data ( self ): raise NotImplementedError def send_data ( self , data ): raise NotImplementedError def handle ( self ): now = datetime . datetime . utcnow (). strftime ( ‘%Y-%m-%d %H:%M:%S.%f’ ) print » \n \n %s request %s (%s %s):» % ( self . __class__ . __name__ [: 3 ], now , self . client_address [ 0 ], self . client_address [ 1 ]) try : data = self . get_data () print len ( data ), data . encode ( ‘hex’ ) # repr(data).replace(‘\\x’, »)[1:-1] self . send_data ( dns_response ( data )) except Exception : traceback . print_exc ( file = sys . stderr ) class TCPRequestHandler ( BaseRequestHandler ): def get_data ( self ): data = self . request . recv ( 8192 ). strip () sz = int ( data [: 2 ]. encode ( ‘hex’ ), 16 ) if sz < len ( data ) - 2 : raise Exception ( «Wrong size of TCP packet» ) elif sz > len ( data ) — 2 : raise Exception ( «Too big TCP packet» ) return data [ 2 :] def send_data ( self , data ): sz = hex ( len ( data ))[ 2 :]. zfill ( 4 ). decode ( ‘hex’ ) return self . request . sendall ( sz + data ) class UDPRequestHandler ( BaseRequestHandler ): def get_data ( self ): return self . request [ 0 ]. strip () def send_data ( self , data ): return self . request [ 1 ]. sendto ( data , self . client_address ) if __name__ == ‘__main__’ : print «Starting nameserver. « servers = [ SocketServer . ThreadingUDPServer (( » , PORT ), UDPRequestHandler ), SocketServer . ThreadingTCPServer (( » , PORT ), TCPRequestHandler ), ] for s in servers : thread = threading . Thread ( target = s . serve_forever ) # that thread will start one more thread for each request thread . daemon = True # exit the server thread when the main thread terminates thread . start () print «%s server loop running in thread: %s» % ( s . RequestHandlerClass . __name__ [: 3 ], thread . name ) try : while 1 : time . sleep ( 1 ) sys . stderr . flush () sys . stdout . flush () except KeyboardInterrupt : pass finally : for s in servers : s . shutdown () Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A simple implementation of a DNS server in Python.
akapila011/DNS-Server
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
A Domain Name Server that allows you to use your own domain name IP address mappings. This could be used within private networks to simplify sharing of resources within the network.
The application requires Python 3.x to run (tested with version 3.6).
To use the server there are 2 basic steps to follow:
Step 1: You must first generate a zone file. This is the file that stores the domain name and it’s IP address mapping. To generate a zone file you must create a file with the following filename format: [domain name in reverse order].zone. Examples:
- The zone file for www.google.com will be google.com.zone
- The zone file for www.bing.co.uk will be bing.co.uk.zone
- The zone file for www.university.ac.co will be university.ac.co.zone
Ensure the file has a ‘.zone’ extension rather than .txt or any other extension
An example zone file is provided in the project. You can simply copy the detail inside and change the relevant fields for your own mapping. In particular you will need to change the domains in the following fields:
Ensure the domain names placed in the fields match with the filename to avoid errors Finally the ‘a’ field holds 3 records for the IP address mapped to the domain name. Ensure you change them to the correct IP address.
Step 2: Once the zone file is created and placed in the ‘Zones’ directory you can start the server. No special modifications are needed to run the server. You can simply run the ‘Server.py’ file. Ensure that you run the ‘Server.py’ with the necessary privileges required for the program to access network resources.
Note: The server uses the default DNS server port (53). Ensure no other process is using port 53 or else the server will not be able to run.
Now you can change the network configurations on various machines that need to use this DNS server by specifying the IP address of the machine running the DNS server.
To see an example run you can use the ‘dig’ command on Linux to see the response the server provides.
- Start the server and ensure it is running before proceeding
- Open a terminal and enter use the following command
You should receive a response for the domain xyz.com Once you have set your own zone file you can replace ‘xyz.com’ with your own domain name. You can change the IP address ‘127.0.0.1’ to the IP address where the DNS server is running when you have it running on a remote machine on the network.
Note: if you have updated your network configurations to use a specific IP for the dns server then there is no need to include the ‘@127.0.0.1’ portion in the command.
If you make any modifications to the code you can run tests by navigating to the project directory (i.e. ‘DNS Server’) and then run following command: