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-Query: www.facebook.com.
[0]A-Query: blah.facebook.com.
[0]A-Query: fb.me.
[0]A-Query: amazon.ca.

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

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

3 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 )

Facebook photo

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

Connecting to %s