2017-06-14 19:05:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/lxn/walk"
|
|
|
|
"github.com/marcsauter/single"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func get_ip() (string, error) {
|
2018-08-21 12:15:55 +00:00
|
|
|
resp, err := http.Get("https://ifconfig.co/ip")
|
2017-06-14 19:05:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
ip := fmt.Sprintf("%s", body)
|
|
|
|
return ip, err
|
|
|
|
}
|
|
|
|
|
2017-06-16 18:15:12 +00:00
|
|
|
func err_fatal(err error) {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-14 19:05:47 +00:00
|
|
|
var old_ip string
|
2017-06-18 17:24:12 +00:00
|
|
|
var old_t string
|
2017-06-14 19:05:47 +00:00
|
|
|
|
|
|
|
func main() {
|
2017-06-14 19:18:31 +00:00
|
|
|
single_proc := single.New("IP Checker")
|
2017-06-14 19:05:47 +00:00
|
|
|
single_proc.Lock()
|
|
|
|
defer single_proc.Unlock()
|
|
|
|
|
|
|
|
mw, err := walk.NewMainWindow()
|
2017-06-16 18:15:12 +00:00
|
|
|
err_fatal(err)
|
2017-06-14 19:05:47 +00:00
|
|
|
|
|
|
|
icon, err := walk.NewIconFromResourceId(9)
|
2017-06-16 18:15:12 +00:00
|
|
|
err_fatal(err)
|
2017-06-14 19:05:47 +00:00
|
|
|
|
|
|
|
ni, err := walk.NewNotifyIcon()
|
2017-06-16 18:15:12 +00:00
|
|
|
err_fatal(err)
|
2017-06-14 19:05:47 +00:00
|
|
|
defer ni.Dispose()
|
|
|
|
|
2017-06-16 18:15:12 +00:00
|
|
|
err_fatal(ni.SetIcon(icon))
|
2017-06-14 19:05:47 +00:00
|
|
|
|
|
|
|
exitAction := walk.NewAction()
|
2017-06-16 18:15:12 +00:00
|
|
|
err_fatal(exitAction.SetText("E&xit"))
|
|
|
|
|
2017-06-14 19:05:47 +00:00
|
|
|
exitAction.Triggered().Attach(func() { walk.App().Exit(0) })
|
2017-06-16 18:15:12 +00:00
|
|
|
err_fatal(ni.ContextMenu().Actions().Add(exitAction))
|
2017-06-14 19:05:47 +00:00
|
|
|
|
2017-06-16 18:15:12 +00:00
|
|
|
err_fatal(ni.SetVisible(true))
|
2017-06-14 19:05:47 +00:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
first_loop := true
|
|
|
|
for first_loop {
|
|
|
|
ip, ip_err := get_ip()
|
|
|
|
if ip_err == nil {
|
|
|
|
first_loop = false
|
|
|
|
old_ip = ip
|
2017-06-18 17:24:12 +00:00
|
|
|
old_t = fmt.Sprint(time.Now().Format("_2 15:04:05"))
|
2017-06-16 18:15:12 +00:00
|
|
|
err_fatal(ni.ShowCustom(
|
2017-06-14 19:05:47 +00:00
|
|
|
"IP Checker",
|
2017-06-18 17:24:12 +00:00
|
|
|
old_t+" Current IP is "+old_ip))
|
|
|
|
err_fatal(ni.SetToolTip(old_t + " Current IP is " + old_ip))
|
2017-06-14 19:05:47 +00:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
time.Sleep(time.Second * 60)
|
|
|
|
ip, ip_err := get_ip()
|
|
|
|
if ip_err == nil {
|
|
|
|
if old_ip != ip {
|
2017-06-18 17:24:12 +00:00
|
|
|
t := fmt.Sprint(time.Now().Format("_2 15:04:05"))
|
2017-06-16 18:15:12 +00:00
|
|
|
err_fatal(ni.ShowCustom(
|
2017-06-14 19:05:47 +00:00
|
|
|
"IP Checker",
|
2017-06-18 17:24:12 +00:00
|
|
|
t+" - "+ip+"\n"+old_t+" - "+old_ip))
|
|
|
|
err_fatal(ni.SetToolTip(t + " - " + ip + "\n" + old_t + " - " + old_ip))
|
2017-06-14 19:05:47 +00:00
|
|
|
|
|
|
|
old_ip = ip
|
2017-06-18 17:24:12 +00:00
|
|
|
old_t = t
|
2017-06-14 19:05:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
mw.Run()
|
|
|
|
}
|