IPv6 hosts check
This commit is contained in:
29
pkg/hosts/hosts.go
Normal file
29
pkg/hosts/hosts.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package hosts
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
IPV4 = "https://gist.githubusercontent.com/yowmamasita/d0c1c7353500d0928cb5242484e8ed06/raw/ipv4.txt"
|
||||
IPV6 = "https://gist.githubusercontent.com/yowmamasita/d0c1c7353500d0928cb5242484e8ed06/raw/ipv6.txt"
|
||||
)
|
||||
|
||||
func FetchHosts(url string) ([]string, error) {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var ips []string
|
||||
scanner := bufio.NewScanner(resp.Body)
|
||||
for scanner.Scan() {
|
||||
ips = append(ips, scanner.Text())
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ips, nil
|
||||
}
|
||||
Reference in New Issue
Block a user