mirror of
https://github.com/davegallant/vpngate.git
synced 2026-01-14 22:24:05 +00:00
Add support for HTTP/HTTPS proxies
This commit is contained in:
14
README.md
14
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 <https://ipinfo.io>, 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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user