Updates #6541.
Squashed commit of the following:
commit e79507f6a7850cc3af316f0e46c289a84882ae15
Merge: 1a09de91d d32832735
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Mon Dec 18 14:29:21 2023 +0300
Merge branch 'master' into 6541-hosts-nodata
commit 1a09de91dc211e03a104ee7c58b7ea39498b73dd
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Dec 14 18:24:56 2023 +0300
filtering: separate files
commit e00d1d26c79c85d9266ccdb5e5b4c4a4fde2c90c
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Dec 14 18:00:52 2023 +0300
filtering: fix hosts nodata
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)
}
}