GO Programming – DNS Server – Blocker/Forwarder

Browser Extension: fossjon.wp.com/2020/09/15/…browser-extensions/

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 Code: 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

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

Leave a comment