Browse Source

include public ip by default

make_cert_optional
Otto Suess 7 years ago
parent
commit
1f1e69b34a
No known key found for this signature in database GPG Key ID: 354749C62B4BAC41
  1. 22
      zapconnect.go

22
zapconnect.go

@ -8,6 +8,9 @@ import (
"github.com/Baozisoftware/qrcode-terminal-go"
"encoding/json"
b64 "encoding/base64"
"net/http"
"os"
"strings"
)
type certificates struct {
@ -31,6 +34,23 @@ func getLocalIP() string {
return ""
}
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 ""
}
func main() {
ipPtr := flag.Bool("i", false, "Include local ip in QRCode.")
jsonPtr := flag.Bool("j", false, "Generate json instead of a QRCode.")
@ -53,6 +73,8 @@ func main() {
ipString := ""
if *ipPtr {
ipString = getLocalIP() + ":10009"
} else {
ipString = getPublicIP() + ":10009"
}
cert := &certificates{

Loading…
Cancel
Save