GO Programming – DNS Server – Blocker/Forwarder

I haven’t posted much GO related code on this blog before as I am more of a fan of C, Python, Java/JS, etc. I initially found its syntax to be a bit harder to read due to the variable typing being placed after the variable name. It can make it harder to track and understand if the variable you’re looking at is a: mutable or immutable, pointer or constant, array or singular, referenced or dereferenced, local or global, etc.

It does combine a lot of power that you would typically find in a more structured language (like Java) along with being flexibile and relaxed (like Python).

Anyway, I’ve been trying to learn its syntax and capabilities recently and I created a basic GO program which runs on a DNS server framework (github dependency). It reads in a regex based domain blocklist text file and it also forwards the rest of the queries on for regular resolution.

Source: https://github.com/stoops/dnsrb/blob/main/dnsrb.go

$ go run dnsrb.go

Starting: 53053
Reading file [1616610565]...
[0]A-Query: facebook.com.
[0]A-Reply: 127.0.0.1
[0]A-Query: www.facebook.com.
[0]A-Reply: 127.0.0.1
[0]A-Query: blah.facebook.com.
[0]A-Reply: 127.0.0.1
[0]A-Query: fb.me.
[0]A-Reply: 127.0.0.1
[0]A-Query: amazon.ca.
[0]A-Reply: 54.239.18.172
[1]A-Reply: 54.239.19.238
[2]A-Reply: 52.94.225.242

$ echo ; for d in facebook.com www.facebook.com blah.facebook.com fb.me amazon.ca ; do echo "[$d] -> $(dig @127.0.0.1 -p 53053 $d +short)" ; done ; echo

[facebook.com] -> 127.0.0.1
[www.facebook.com] -> 127.0.0.1
[blah.facebook.com] -> 127.0.0.1
[fb.me] -> 127.0.0.1
[amazon.ca] -> 54.239.18.172 54.239.19.238 52.94.225.242
GO Programming – DNS Server – Blocker/Forwarder

2 thoughts on “GO Programming – DNS Server – Blocker/Forwarder

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s