mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-16 10:28:29 -07:00
579177fc70
Close #1451 Squashed commit of the following: commit 91e5c98d7543b7c8872cc494818d66bb823ec7c0 Author: Simon Zolin <s.zolin@adguard.com> Date: Thu Mar 5 13:09:01 2020 +0300 fix commit 4f80865e55f27206fa9cef1d72fb3652498da582 Author: Simon Zolin <s.zolin@adguard.com> Date: Thu Mar 5 13:08:31 2020 +0300 * fix race-detector issue commit 5513c6c12c112c8f9325dbc8a8d09e58fe7611e0 Author: Simon Zolin <s.zolin@adguard.com> Date: Thu Mar 5 13:01:46 2020 +0300 - dnsfilter: fix hanging on error commit c7b81286833a523349efb8ca972eba3540518944 Author: Simon Zolin <s.zolin@adguard.com> Date: Thu Mar 5 12:42:19 2020 +0300 * DNS: use "unrestricted" Quad9 servers |
||
---|---|---|
.. | ||
tests | ||
dnsfilter_test.go | ||
dnsfilter.go | ||
README.md | ||
rewrites.go | ||
safesearch.go | ||
security.go |
AdGuard Home's DNS filtering go library
Example use:
[ -z "$GOPATH" ] && export GOPATH=$HOME/go
go get -d github.com/AdguardTeam/AdGuardHome/dnsfilter
Create file filter.go
package main
import (
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
"log"
)
func main() {
filter := dnsfilter.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 '%s': %s", host, err)
}
if res.IsFiltered {
log.Printf("Host %s is filtered, reason - '%s', matched rule: '%s'", host, res.Reason, res.Rule)
} else {
log.Printf("Host %s is not filtered, reason - '%s'", 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/dnsfilter"
"log"
)
func main() {
filter := dnsfilter.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 '%s': %s", host, err)
}
if res.IsFiltered {
log.Printf("Host %s is filtered, reason - '%s', matched rule: '%s'", host, res.Reason, res.Rule)
} else {
log.Printf("Host %s is not filtered, reason - '%s'", host, res.Reason)
}
}