Files
AdGuardHome/internal/filtering
Stanislav Chzhen 3b846bae6e Pull request 1998: upd-proj-skel
Squashed commit of the following:

commit 5cc2914b18fd71ff83e2872ef6755f2ff56d653c
Merge: bf14a513e 085b4fdce
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Sep 7 14:58:44 2023 +0300

    Merge branch 'master' into upd-proj-skel

commit bf14a513eb46ebf2c2809246603b071e6c334e9f
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Sep 7 14:47:10 2023 +0300

    all: imp code

commit ec3f7a88b86b3f423193aa95c2e820bcd86fdef3
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Sep 7 14:28:39 2023 +0300

    scripts: upd go lint

commit 6a9342f6058bc21252f97045f7015440f013cb09
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Sep 7 14:13:17 2023 +0300

    all: upd proj skel
2023-09-07 15:05:21 +03:00
..
2023-09-07 15:05:21 +03:00
2023-07-20 14:26:35 +03:00
2023-09-04 17:18:43 +03:00
2023-09-04 17:18:43 +03:00
2023-09-04 17:18:43 +03:00
2023-09-04 17:18:43 +03:00
2023-09-04 17:18:43 +03:00
2023-09-07 14:57:28 +03:00

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