reason-dns-toys is a lightweight DNS utility server built in ReasonML. Inspired by the dns.toys
project, this library offers various utilities accessible via DNS queries, such as time, weather, and more. It's designed for fun and experimental use cases while showcasing the power of ReasonML.
-
Lightweight and Efficient: Built with ReasonML, the library ensures type safety and functional programming benefits without unnecessary overhead.
-
Extendable Utilities: Easily add or customize DNS-based services to fit your needs.
-
Learning Opportunity: Understand DNS protocols and ReasonML while building something functional and fun.
-
Practical Use Cases: Serve quick data like time, weather, or custom queries in a unique and stateless way.
- Query current time.
- Fetch basic weather information.
- Extendable architecture to add custom utilities.
- Built using ReasonML for type safety and functional programming benefits.
To run or develop this project, you need:
- ReasonML/ReScript: Set up your environment using the official guide.
- Node.js (optional, for DNS bindings).
Clone the repository:
git clone https://github.com/your-username/reason-dns-toys.git
cd reason-dns-toys
Install dependencies:
npm install
Start the DNS server:
npm start
The server will run locally on 127.0.0.1:5353
.
Use dig
or similar tools to test the DNS utilities:
-
Time Query:
dig @127.0.0.1 -p 5353 time.example.com
-
Weather Query:
dig @127.0.0.1 -p 5353 weather.example.com
- For a time query, you'll receive the current UTC time.
- For a weather query, you'll receive a placeholder response like
Sunny 25°C
(customizable).
reason-dns-toys/
├── src/
│ ├── DNS.re # DNS parsing and query handling
│ ├── Services.re # Time, weather, and other utilities
│ └── Server.re # Main server logic
├── package.json # Project metadata and scripts
├── bsconfig.json # Build configuration
└── README.md # Project documentation
You can easily add new DNS-based utilities:
-
Define your logic in
Services.re
:let getCustomService = (): string => { "This is a custom service response."; };
-
Register the service in
Server.re
:switch (parsedQuery) { | "custom" => Services.getCustomService() | _ => "Unknown service" };
-
Test your new query:
dig @127.0.0.1 -p 5353 custom.example.com
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Commit your changes (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature/your-feature
). - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
-
Inspired by dns.toys, a lightweight DNS server by knadh. Many thanks for the inspiration and the original idea.
-
Built with ReasonML for a type-safe and functional programming experience.
Official ReScript starter template.
npm install
- Build:
npm run res:build
- Clean:
npm run res:clean
- Build & watch:
npm run res:dev
node src/Demo.res.js