File size: 871 Bytes
d2f89dd |
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 |
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()
}
|