Browse Source
fix #5: use glendc/go-external-ip to get external ip
make_cert_optional
Otto Suess
6 years ago
No known key found for this signature in database
GPG Key ID: F7EFC44C2C240A11
1 changed files with
9 additions and
16 deletions
-
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") |
|
|
|
if err != nil { |
|
|
|
os.Stderr.WriteString(err.Error()) |
|
|
|
os.Stderr.WriteString("\n") |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
defer resp.Body.Close() |
|
|
|
|
|
|
|
if resp.StatusCode == http.StatusOK { |
|
|
|
bodyBytes, _ := ioutil.ReadAll(resp.Body) |
|
|
|
return strings.TrimSpace(string(bodyBytes)) |
|
|
|
} |
|
|
|
|
|
|
|
return "" |
|
|
|
consensus := externalip.DefaultConsensus(nil, nil) |
|
|
|
ip, err := consensus.ExternalIP() |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
|
|
|
|
return ip.String() |
|
|
|
} |
|
|
|
|
|
|
|
func main() { |
|
|
|