30 lines
603 B
Go
30 lines
603 B
Go
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
|
|
}
|