|
package main |
|
|
|
import ( |
|
"fmt" |
|
"github.com/NoahShen/gotunnelme/src/gotunnelme" |
|
"io/ioutil" |
|
"net/http" |
|
"os" |
|
"strconv" |
|
) |
|
|
|
func getExternalIP() (string, error) { |
|
resp, err := http.Get("http://ipinfo.io/ip") |
|
if err != nil { |
|
return "", err |
|
} |
|
defer resp.Body.Close() |
|
ip, err := ioutil.ReadAll(resp.Body) |
|
if err != nil { |
|
return "", err |
|
} |
|
return string(ip), nil |
|
} |
|
|
|
func main() { |
|
if len(os.Args) == 1 { |
|
fmt.Fprintln(os.Stderr, "Usage: go_localt <local port>") |
|
os.Exit(1) |
|
} |
|
localPort, err := strconv.Atoi(os.Args[1]) |
|
if err != nil { |
|
fmt.Fprintln(os.Stderr, err) |
|
os.Exit(1) |
|
} |
|
|
|
t := gotunnelme.NewTunnel() |
|
url, err := t.GetUrl("") |
|
if err != nil { |
|
panic(err) |
|
} |
|
fmt.Println(url) |
|
|
|
extIP, err := getExternalIP() |
|
if err != nil { |
|
panic(err) |
|
} |
|
fmt.Println(extIP) |
|
|
|
err = t.CreateTunnel(localPort) |
|
if err != nil { |
|
panic(err) |
|
} |
|
t.StopTunnel() |
|
} |
|
|