Skip to content

Commit 4cb3413

Browse files
committed
First init
0 parents  commit 4cb3413

File tree

9 files changed

+195
-0
lines changed

9 files changed

+195
-0
lines changed

go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module southplus-probe
2+
3+
go 1.18
4+
5+
require golang.org/x/sys v0.21.0 // direct
6+
7+
require (
8+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
9+
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2 // indirect
10+
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
2+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
3+
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
4+
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5+
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2 h1:MZF6J7CV6s/h0HBkfqebrYfKCVEo5iN+wzE4QhV3Evo=
6+
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2/go.mod h1:s1Sn2yZos05Qfs7NKt867Xe18emOmtsO3eAKbDaon0o=

main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"southplus-probe/task"
7+
"southplus-probe/utils"
8+
)
9+
10+
func main() {
11+
url := flag.String("url", "https://south-plus.org/register.php", "")
12+
fmt.Println(*url)
13+
utils.Set_auto_start()
14+
task.Start(url)
15+
}

network/net.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package network
2+
3+
import (
4+
"io"
5+
"log"
6+
"net/http"
7+
)
8+
9+
func Req(url string) []byte {
10+
client := &http.Client{}
11+
12+
// 创建HTTP请求
13+
req, err := http.NewRequest("GET", url, nil)
14+
if err != nil {
15+
log.Fatalf("Error creating request: %v", err)
16+
}
17+
18+
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36")
19+
20+
resp, err := client.Do(req)
21+
if err != nil {
22+
log.Fatalf("Error making request: %v", err)
23+
}
24+
defer resp.Body.Close()
25+
26+
// 读取响应体
27+
body, err := io.ReadAll(resp.Body)
28+
if err != nil {
29+
log.Fatalf("Error reading response body: %v", err)
30+
}
31+
return body
32+
}

readme.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# South-plus 注册开放检测
2+
3+
每24小时自动检测 South-plus 是否开放注册,并弹出消息通知
4+
5+
运行环境:Windows 10+
6+
7+
8+
# 命令
9+
10+
开启或关闭程序自启动(默认为开启):
11+
12+
```
13+
s -autostart
14+
```
15+
16+
```
17+
s hn
18+
```
19+
20+
21+
22+

task/notify.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package task
2+
3+
import (
4+
"log"
5+
6+
"gopkg.in/toast.v1"
7+
)
8+
9+
func notify() {
10+
notification := toast.Notification{
11+
AppID: "Southplus-probe",
12+
Title: "Southplus已开放注册",
13+
Message: "请前去网站进行注册吧",
14+
Actions: []toast.Action{
15+
{"protocol", "注册", ""},
16+
},
17+
}
18+
err := notification.Push()
19+
if err != nil {
20+
log.Fatal("Err pushing notification", err)
21+
}
22+
}

task/task.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package task
2+
3+
import (
4+
"fmt"
5+
"southplus-probe/network"
6+
"strings"
7+
"time"
8+
)
9+
10+
func check(url *string) bool {
11+
html := network.Req(*url)
12+
if strings.Contains(string(html), "Member only knows") {
13+
fmt.Println("\033[31m注册未开放 :(")
14+
return false
15+
} else {
16+
fmt.Println("\033[32m注册已开放")
17+
return true
18+
}
19+
}
20+
21+
func Start(url *string) {
22+
check(url)
23+
fmt.Println("\033[0m正在后台运行中... 将在24小时后进行下一次检测")
24+
ticker := time.NewTicker(24 * time.Hour)
25+
defer ticker.Stop()
26+
for {
27+
select {
28+
case <-ticker.C:
29+
fmt.Println("\033[0m开始测试...")
30+
if check(url) {
31+
ticker.Stop()
32+
notify_in_loop()
33+
}
34+
}
35+
}
36+
}
37+
38+
func notify_in_loop() {
39+
ticker := time.NewTicker(5 * time.Minute)
40+
defer ticker.Stop()
41+
for {
42+
select {
43+
case <-ticker.C:
44+
notify()
45+
}
46+
}
47+
}

utils/linux.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build linux
2+
3+
package utils
4+
5+
func Set_auto_start() {
6+
7+
}

utils/windows.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//go:build windows
2+
3+
package utils
4+
5+
import (
6+
"log"
7+
"os"
8+
"path/filepath"
9+
10+
"golang.org/x/sys/windows/registry"
11+
)
12+
13+
func Set_auto_start() {
14+
exePath, err := os.Executable()
15+
if err != nil {
16+
log.Fatalf("获取可执行文件路径失败: %v", err)
17+
}
18+
absPath, err := filepath.Abs(exePath)
19+
if err != nil {
20+
log.Fatalf("获取绝对路径失败: %v", err)
21+
}
22+
23+
k, err := registry.OpenKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Run`, registry.ALL_ACCESS)
24+
if err != nil {
25+
log.Fatalf("打开注册表键失败: %v", err)
26+
}
27+
defer k.Close()
28+
29+
err = k.SetStringValue("Southplus-probe", absPath)
30+
if err != nil {
31+
log.Fatalf("设置注册表值失败: %v", err)
32+
}
33+
34+
}

0 commit comments

Comments
 (0)