DNS Toys: Daily use Tools and Utilities over the DNS Protocol

DNS Toys is an open-source tool to help you manage all the little queries you have from your command prompt by taking advantage of the DNS protocol.

It helps you find the public IP, weather, world time, timezone, conversion rate, etc., within your terminal instead of browsing.

Install Dig Utility on Linux

The dig command should be present in your system to use this tool for fetching data from the DNS protocol.

By default, all Linux distributions provide this tool. If you do not have it, follow any of the below-mentioned methods depending upon the distribution you use to install the dig utility on your Linux system.

$ sudo apt install dnsutils         # For Ubuntu/Debian-based distributions
$ sudo dnf install bind-utils       # For RHEL/Fedora-based distributions
$ sudo pacman -Sy dnsutils          # For Arch/Manjaro-based distributions

After the installation is done, you can follow the usage of the DNS toys to make things easier via the command prompt.

DNS Toys Usage

The first thing you need to understand is the output of this tool. When you execute the dig command with the queries, it resolves them and prints the output on your screen.

This output contains the header, question section, answer section, and footer (query time, server IP, date, and msg size), as shown below.

DNS Toys output
DNS Toys output

Let’s also get familiar with the help section of this tool by using the below command.

$ dig help @dns.toys

Below is the output of the above command.

DNS Toys help section
DNS Toys help section

In the help section, each command with a usage definition is provided, but we will also explore each one.

Display the public IP using the DNS Toys

In our previous article, we discussed how to display public IP address using the command line in Linux. If you read, you know that finding the public IP address using the DNS protocol is one of the fastest ways.

Execute the below command to use the DNS Toys server for fetching the public IP address of your network.

$ dig ip @dns.toys

Check the World Time using the DNS Toys

You can pass the city name by attaching .time at the end to fetch the current time of the specified city, as shown below.

$ dig mumbai.time @dns.toys
$ dig california.time @dns.toys
$ dig paris/fr.time @dns.toys 

Check the weather using DNS Toys

Following the same pattern earlier, just by changing the .time to .weather, you can output the weather of the specified city, as shown below.

$ dig mumbai.weather @dns.toys
$ dig california.weather @dns.toys
$ dig amsterdam/nl.weather @dns.toys

Internally this tool uses yr.no service to output the weather, due to which sometimes you might see the message “weather data is being fetched. Try again in a few seconds.“, at that time, re-execute the same command for the output.

Convert Units using the DNS Toys

Unit conversion is one of the requirements for me to open a clunky search page that is now replaced by the DNS Toys. To convert any unit, define the $Value$FromUnit-$ToUnit to get the output, as shown below.

$ dig 1h-min.unit @dns.toys                   # Convert 1 Hour into 60 Minutes
$ dig 2min-s.unit @dns.toys                   # Convert 2 Minute into 120 Seconds
$ dig 1mph-kmph.unit @dns.toys                # Convert 1 Mile/hour into 1.61 Kilometer/hour
$ dig 2cm-m.unit @dns.toys                    # Convert 2 Centimeter into 0.02 Meter
$ dig 4GB-MB.unit @dns.toys                   # Convert 4 Gigabyte into 4000 Megabyte

Execute the below command to list the other 70 units for conversion.

$ dig unit @dns.toys

Currency conversion (forex) using the DNS Toys

Converting the currency of two countries or cryptocurrency can be quickly done using the DNS Toys by following the pattern $Value$FromCurrency-$ToCurrency as follows.

$ dig 1USD-INR.fx @dns.toys                    # Convert Dollor into INR
$ dig 1BTC-INR.fx @dns.toys                    # Convert Bitcoin into INR
$ dig 1RUB-INR.fx @dns.toys                    # Convert Rubble into INR
$ dig 1CAD-INR.fx @dns.toys                    # Convert Canadian Dollor into INR
$ dig 1GBP-INR.fx @dns.toys                    # Convert Pound to INR

The API service is taken from exchangerate.host for the conversion.

Convert numbers to words using DNS Toys

It might not be as helpful as the others, but you can easily convert any number into words using the DNS Toys.

$ dig 985545752.words @dns.toys
$ dig 564878956.words @dns.toys

Parse CIDR notation using the DNS Toys

Parsing CIDR (Classless Inter-Domain Routing) notation for finding the first and last usable IP addresses in the subnet can be quickly done using the DNS Toys.

$ dig 10.0.0.0/24.cidr @dns.toys
$ dig 2001:db8::/108.cidr @dns.toys

Number Base Conversion using the DNS Toys

Converting a number from one base to another from the supported bases hex, dec, oct and bin can be easily achieved using the DNS Toys.

$ dig 55oct-bin.base @dns.toys
$ dig 4hex-bin.base @dns.toys

Making Things Easier

Everything is cool until you do not have to memorize all of these commands on your own. Once that happens, all of the pluses of this utility decrease. Why use such a tool if you have to memorize all of these commands?

Hold on a minute; you can easily create a function that works as an abbreviation for this command, making it easier for you to work with this utility.

There is a shell function you can add to your shell configuration file to make it simple for you to use DNS Toys. First, find out your current shell using the below command.

$ printenv SHELL
OR
$ echo 0

Below is the output of the above command.

Finding the default shell
Finding the default shell

For me, the default shell is bash, so the configuration file for the bash shell is at ~/.bashrc. Add the below shell function at the end of the configuration file.

function dy { dig +noall +answer +additional "$1" @dns.toys; }

For the fish shell, the configuration file that needs to be edited is located in the ~/.config/fish/config.fish path. Open it with your favourite text editor and add the below line at the end of the file.

alias dy="dig +noall +answer +additional $argv[1] @dns.toys"

Once you are done, reload the configuration file using the source ~/.bashrc for the bash shell and source ~/.config/fish/config.fish for the fish shell.

Finally, you can use the dy command as a shortcut.

$ dy california.time
$ dy mumbai.weather
$ dy 1USD-INR.fx

Wrap Up

It is an excellent tool for users who use the terminal for their daily work. Still, the developer of this tool clearly mentioned that this tool does not guarantee to provide accuracy, timeliness, reliability, appropriateness, or completeness of any services or data.

While using this tool, I have not faced any issues other than minor changes in the unit and latency. If you have any questions about this tool, feel free to ask in the comment section or on Github issues.

0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Grant
Grant
11 months ago

Would be good idea together with weather also to add a service for TIDES FORECAST (and current TIDE state) for locations in the world.