diff --git a/README.md b/README.md index 2acd6ce..0301a14 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This is a client for [vpngate.net](https://www.vpngate.net/). This client fetches the list of available relay servers provided by vpngate.net, and allows you to filter and connect to a server of your liking. -You can check out your current IP address and region at https://ipinfo.io, or run the following: +You can check out your current IP address and region at , or run the following: ```shell curl ipinfo.io @@ -81,6 +81,18 @@ sudo vpngate connect --random #### Proxy +In some cases, anonymity is necessary to populate the list of available VPN servers. + +A proxy is a way to bypass restrictions and in some cases, internet censorship. + +##### HTTP/HTTPS + +Use the specified HTTP/HTTPS proxy to fetch the server list. + +```shell +sudo vpngate connect --proxy "http://localhost:8080" +``` + ##### SOCKS5 Use the specified SOCKS5 proxy to fetch the server list. diff --git a/cmd/connect.go b/cmd/connect.go index 01cc2ed..9c1c9bc 100644 --- a/cmd/connect.go +++ b/cmd/connect.go @@ -18,13 +18,15 @@ import ( var ( flagRandom bool flagReconnect bool + flagProxy string flagSocks5Proxy string ) func init() { connectCmd.Flags().BoolVarP(&flagRandom, "random", "r", false, "connect to a random server") connectCmd.Flags().BoolVarP(&flagReconnect, "reconnect", "t", false, "continually attempt to connect to the server") - connectCmd.Flags().StringVarP(&flagSocks5Proxy, "socks5", "s", "", "provide a socks5 proxy server to connect through (i.e. 127.0.0.1:1080") + connectCmd.Flags().StringVarP(&flagProxy, "proxy", "p", "", "provide a http/https proxy server to make requests through (i.e. 127.0.0.1:8080") + connectCmd.Flags().StringVarP(&flagSocks5Proxy, "socks5", "s", "", "provide a socks5 proxy server to make requests through (i.e. 127.0.0.1:1080") rootCmd.AddCommand(connectCmd) } @@ -35,7 +37,7 @@ var connectCmd = &cobra.Command{ Long: `Connect to a vpn from a list of relay servers`, Args: cobra.RangeArgs(0, 1), Run: func(cmd *cobra.Command, args []string) { - vpnServers, err := vpn.GetList(flagSocks5Proxy) + vpnServers, err := vpn.GetList(flagProxy, flagSocks5Proxy) if err != nil { log.Fatal().Msgf(err.Error()) os.Exit(1) diff --git a/cmd/list.go b/cmd/list.go index 5797bd7..50ae746 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -22,7 +22,7 @@ var listCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - vpnServers, err := vpn.GetList(flagSocks5Proxy) + vpnServers, err := vpn.GetList(flagProxy, flagSocks5Proxy) if err != nil { log.Fatal().Msgf(err.Error()) os.Exit(1) diff --git a/pkg/vpn/list.go b/pkg/vpn/list.go index 23c6d5c..9edff34 100644 --- a/pkg/vpn/list.go +++ b/pkg/vpn/list.go @@ -4,6 +4,7 @@ import ( "bytes" "io" "net/http" + "net/url" "os" "github.com/jszwec/csvutil" @@ -57,7 +58,7 @@ func parseVpnList(r io.Reader) (*[]Server, error) { } // GetList returns a list of vpn servers -func GetList(socks5Proxy string) (*[]Server, error) { +func GetList(httpProxy string, socks5Proxy string) (*[]Server, error) { cacheExpired := vpnListCacheIsExpired() var servers *[]Server @@ -78,7 +79,21 @@ func GetList(socks5Proxy string) (*[]Server, error) { log.Info().Msg("Fetching the latest server list") - if socks5Proxy != "" { + if httpProxy != "" { + proxyURL, err := url.Parse(httpProxy) + if err != nil { + log.Error().Msgf("Error parsing proxy:", err) + os.Exit(1) + } + transport := &http.Transport{ + Proxy: http.ProxyURL(proxyURL), + } + + client = &http.Client{ + Transport: transport, + } + + } else if socks5Proxy != "" { dialer, err := proxy.SOCKS5("tcp", socks5Proxy, nil, proxy.Direct) if err != nil { log.Error().Msgf("Error creating SOCKS5 dialer: %v", err)