-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
58 lines (47 loc) · 1.2 KB
/
main.go
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
50
51
52
53
54
55
56
57
58
package main
import (
"flag"
"fmt"
"log"
"github.com/mtojek/ohlavpn/ipapi"
"github.com/mtojek/ohlavpn/vpn"
)
func main() {
var countryCode string
var limit int
var geoIP bool
var verify bool
flag.StringVar(&countryCode, "c", "us", "country code")
flag.IntVar(&limit, "l", 5, "proxy server limit")
flag.BoolVar(&geoIP, "g", false, "check GeoIP data")
flag.BoolVar(&verify, "v", false, "verify proxy connectivity")
flag.Parse()
vpnClient := vpn.NewClient()
err := vpnClient.Initialize()
if err != nil {
log.Fatalf("Error occurred while initializing VPN API vpnClient: %v", err)
}
tunnels, err := vpnClient.FindTunnels(countryCode, limit)
if err != nil {
log.Fatalf("Error occurred while finding VPN tunnels: %v", err)
}
if len(tunnels.Servers) == 0 {
log.Fatal("No proxy servers found")
}
for _, tunnel := range tunnels.Servers {
fmt.Print(tunnel.String())
if geoIP {
ipAPIClient := ipapi.NewClient()
if verify {
ipAPIClient = ipAPIClient.WithProxy(tunnel.URL())
}
geoIPData, err := ipAPIClient.GeoIP(tunnel.Host)
if err != nil {
fmt.Printf("\terror checking GeoIP data: %v", err)
} else {
fmt.Printf("\t%v", geoIPData.String())
}
}
fmt.Println()
}
}