Compare commits
3 Commits
7702b5a431
...
68eb3a055d
| Author | SHA1 | Date | |
|---|---|---|---|
|
68eb3a055d
|
|||
|
a20d939e0d
|
|||
|
9cda5799e1
|
@@ -46,6 +46,8 @@ func NewConfig(limit uint) Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewConfigWithValidator creates a new Config with the specified validator.
|
// NewConfigWithValidator creates a new Config with the specified validator.
|
||||||
|
// limit is the maximum number of items to process or validate. 0 means no limit.
|
||||||
|
// validator is the IP validator to use.
|
||||||
func NewConfigWithValidator(limit uint, validator parser.IPValidator) Config {
|
func NewConfigWithValidator(limit uint, validator parser.IPValidator) Config {
|
||||||
return Config{
|
return Config{
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
config := blocklist.NewConfig(0)
|
// limit 0 - no limit
|
||||||
|
limit := uint(0)
|
||||||
|
config := blocklist.NewConfig(limit)
|
||||||
ips, err := blocklist.Get(url, pars, config)
|
ips, err := blocklist.Get(url, pars, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -33,7 +35,9 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
config := blocklist.NewConfigWithValidator(0, &parser.IPRangeValidator{})
|
// limit 0 - no limit
|
||||||
|
limit := uint(0)
|
||||||
|
config := blocklist.NewConfigWithValidator(limit, &parser.IPRangeValidator{})
|
||||||
ips, err := blocklist.Get(url, pars, config)
|
ips, err := blocklist.Get(url, pars, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
53
examples/honeypot.go
Normal file
53
examples/honeypot.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"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.projecthoneypot.org/list_of_ips.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
type rssItem struct {
|
||||||
|
Title string `xml:"title"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
url := "https://www.projecthoneypot.org/list_of_ips.php?t=d&rss=1"
|
||||||
|
pars, err := parser.NewRss(func(decoder *xml.Decoder, start xml.StartElement) (string, error) {
|
||||||
|
if start.Name.Local != "item" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var rssItem rssItem
|
||||||
|
if err := decoder.DecodeElement(&rssItem, &start); err != nil {
|
||||||
|
return "", fmt.Errorf("decode rss item: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rssItem.Title == "" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := strings.Split(rssItem.Title, "|")
|
||||||
|
if len(fields) != 2 {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(fields[0]), 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