commit 6c887dea4650f7d15c26363ebfff8d5a3367aaad Author: Igor V Belousov Date: Wed Jun 14 22:05:47 2017 +0300 First commit diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..127a98b --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Igor V Belousov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..dee73df --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +IP Checker +========== + +This program check modify IPv4 address and send notification. + +Only windows platform. +Only for me. ;-) + +Build +----- + +```cmd +go get github.com/akavel/rsrc + +rsrc -manifest ip_checker.manifest.txt -ico icon.ico -o rsrc.syso + +go build -ldflags="-H windowsgui -s -w" +``` + +License +------- + +### Icon +Icon made by Freepik from www.flaticon.com is licensed by CC 3.0 BY + +### Program + +MIT License + +Copyright (c) 2017 Igor V Belousov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/icon.ico b/icon.ico new file mode 100644 index 0000000..fe79110 Binary files /dev/null and b/icon.ico differ diff --git a/ip_checker.manifest.txt b/ip_checker.manifest.txt new file mode 100644 index 0000000..1f24318 --- /dev/null +++ b/ip_checker.manifest.txt @@ -0,0 +1,20 @@ + + + + + + + + + + + true + + + + + + + + + diff --git a/main.go b/main.go new file mode 100644 index 0000000..6ca5776 --- /dev/null +++ b/main.go @@ -0,0 +1,106 @@ +package main + +import ( + "fmt" + "github.com/lxn/walk" + "github.com/marcsauter/single" + "io/ioutil" + "log" + "net/http" + "time" +) + +func get_ip() (string, error) { + resp, err := http.Get("https://4.ifcfg.me/ip") + 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 +} + +var old_ip string + +func main() { + single_proc := single.New("name") + single_proc.Lock() + defer single_proc.Unlock() + + mw, err := walk.NewMainWindow() + if err != nil { + log.Fatal(err) + } + + icon, err := walk.NewIconFromResourceId(9) + if err != nil { + log.Fatal(err) + } + + ni, err := walk.NewNotifyIcon() + if err != nil { + log.Fatal(err) + } + defer ni.Dispose() + + if err := ni.SetIcon(icon); err != nil { + log.Fatal(err) + } + + exitAction := walk.NewAction() + if err := exitAction.SetText("E&xit"); err != nil { + log.Fatal(err) + } + exitAction.Triggered().Attach(func() { walk.App().Exit(0) }) + if err := ni.ContextMenu().Actions().Add(exitAction); err != nil { + log.Fatal(err) + } + + if err := ni.SetVisible(true); err != nil { + log.Fatal(err) + } + + go func() { + first_loop := true + for first_loop { + ip, ip_err := get_ip() + if ip_err == nil { + first_loop = false + old_ip = ip + if err := ni.ShowCustom( + "IP Checker", + " Current IP is "+old_ip); err != nil { + + log.Fatal(err) + } + + go func() { + for { + time.Sleep(time.Second * 60) + ip, ip_err := get_ip() + if ip_err == nil { + if old_ip != ip { + if err := ni.ShowCustom( + "IP Checker", + " Old IP - "+old_ip+" New IP - "+ip); err != nil { + + log.Fatal(err) + } + old_ip = ip + } + } + } + }() + + } + } + + }() + + mw.Run() +} diff --git a/rsrc.syso b/rsrc.syso new file mode 100644 index 0000000..9015bbd Binary files /dev/null and b/rsrc.syso differ