Compare commits
2 Commits
ae2bcc6ddf
...
941e0541bf
| Author | SHA1 | Date | |
|---|---|---|---|
|
941e0541bf
|
|||
|
16f233197d
|
@@ -35,6 +35,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewConfig creates a new Config with default values.
|
// NewConfig creates a new Config with default values.
|
||||||
|
// limit is the maximum number of items to process or validate. 0 means no limit.
|
||||||
func NewConfig(limit uint) Config {
|
func NewConfig(limit uint) Config {
|
||||||
return Config{
|
return Config{
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
|
|||||||
40
examples/spamhaus.go
Normal file
40
examples/spamhaus.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.kor-elf.net/kor-elf-shield/blocklist"
|
||||||
|
"git.kor-elf.net/kor-elf-shield/blocklist/parser"
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An example of how to get a list of bad IP addresses from the service https://www.spamhaus.org/blocklists/do-not-route-or-peer/
|
||||||
|
*/
|
||||||
|
|
||||||
|
type lineJson struct {
|
||||||
|
IP string `json:"cidr"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
url := "https://www.spamhaus.org/drop/drop_v4.json"
|
||||||
|
//url := "https://www.spamhaus.org/drop/drop_v6.json"
|
||||||
|
pars, err := parser.NewJsonLines(func(item json.RawMessage) (string, error) {
|
||||||
|
var line lineJson
|
||||||
|
if err := json.Unmarshal(item, &line); err != nil {
|
||||||
|
return "", fmt.Errorf("unmarshal json item: %w", err)
|
||||||
|
}
|
||||||
|
return line.IP, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
// limit 0 - no limit
|
||||||
|
limit := uint(0)
|
||||||
|
config := blocklist.NewConfig(limit)
|
||||||
|
ips, err := blocklist.Get(url, pars, config)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println(ips)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user