-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathvpn.go
More file actions
49 lines (38 loc) · 1.08 KB
/
vpn.go
File metadata and controls
49 lines (38 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package fetchers
import (
"bufio"
"fmt"
"net/http"
"strings"
)
// VPNFetcher implements the IPRangeFetcher interface for known VPN services.
type VPNFetcher struct{}
func (f VPNFetcher) Name() string {
return "vpn"
}
func (f VPNFetcher) Description() string {
return "Fetches IP ranges of known VPN services."
}
func (f VPNFetcher) FetchIPRanges() ([]string, error) {
const vpnURL = "https://cdn.jsdelivr.net/gh/X4BNet/lists_vpn@main/output/vpn/ipv4.txt"
resp, err := http.Get(vpnURL)
if err != nil {
return nil, fmt.Errorf("failed to fetch VPN IP ranges: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("received non-200 status code from VPN list: %d", resp.StatusCode)
}
var ipRanges []string
scanner := bufio.NewScanner(resp.Body)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if line != "" && !strings.HasPrefix(line, "#") {
ipRanges = append(ipRanges, line)
}
}
if err := scanner.Err(); err != nil {
return nil, fmt.Errorf("error reading VPN IP ranges: %v", err)
}
return ipRanges, nil
}