Browse Source

fix #5: use glendc/go-external-ip to get external ip

make_cert_optional
Otto Suess 6 years ago
parent
commit
3619479f7a
No known key found for this signature in database GPG Key ID: F7EFC44C2C240A11
  1. 17
      zapconnect.go

17
zapconnect.go

@ -7,10 +7,9 @@ import (
"github.com/Baozisoftware/qrcode-terminal-go"
"encoding/json"
b64 "encoding/base64"
"net/http"
"os"
"strings"
"encoding/pem"
"github.com/glendc/go-external-ip"
)
type certificates struct {
@ -35,20 +34,14 @@ func getLocalIP() string {
}
func getPublicIP() string {
resp, err := http.Get("http://ipv4.myexternalip.com/raw")
consensus := externalip.DefaultConsensus(nil, nil)
ip, err := consensus.ExternalIP()
if err != nil {
os.Stderr.WriteString(err.Error())
os.Stderr.WriteString("\n")
fmt.Println(err)
os.Exit(1)
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
bodyBytes, _ := ioutil.ReadAll(resp.Body)
return strings.TrimSpace(string(bodyBytes))
}
return ""
return ip.String()
}
func main() {

Loading…
Cancel
Save