Squashed commit of the following: commit 2611fd57815910c035621879094ab954389f31b4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Nov 1 16:29:06 2024 +0300 dnsforward: imp test commit 5efcfda937da2ce229ae1a3c57d7a4de35ee7caf Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Nov 1 15:54:18 2024 +0300 rulelist: imp docs, tests commit 7a759c46997ed69e931a0a7c4f25820c52660a3f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Nov 1 14:36:08 2024 +0300 all: add filtering storage; upd golibs
AdGuard Home's DNS filtering go library
Example use:
[ -z "$GOPATH" ] && export GOPATH=$HOME/go
go get -d github.com/AdguardTeam/AdGuardHome/filtering
Create file filter.go
package main
import (
"github.com/AdguardTeam/AdGuardHome/filtering"
"log"
)
func main() {
filter := filtering.New()
filter.AddRule("||dou*ck.net^")
host := "www.doubleclick.net"
res, err := filter.CheckHost(host)
if err != nil {
// temporary failure
log.Fatalf("Failed to check host %q: %s", host, err)
}
if res.IsFiltered {
log.Printf("Host %s is filtered, reason - %q, matched rule: %q", host, res.Reason, res.Rule)
} else {
log.Printf("Host %s is not filtered, reason - %q", host, res.Reason)
}
}
And then run it:
go run filter.go
You will get:
2000/01/01 00:00:00 Host www.doubleclick.net is filtered, reason - 'FilteredBlackList', matched rule: '||dou*ck.net^'
You can also enable checking against AdGuard's SafeBrowsing:
package main
import (
"github.com/AdguardTeam/AdGuardHome/filtering"
"log"
)
func main() {
filter := filtering.New()
filter.EnableSafeBrowsing()
host := "wmconvirus.narod.ru" // hostname for testing safebrowsing
res, err := filter.CheckHost(host)
if err != nil {
// temporary failure
log.Fatalf("Failed to check host %q: %s", host, err)
}
if res.IsFiltered {
log.Printf("Host %s is filtered, reason - %q, matched rule: %q", host, res.Reason, res.Rule)
} else {
log.Printf("Host %s is not filtered, reason - %q", host, res.Reason)
}
}