This repository has been archived by the owner on Apr 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
main.go
68 lines (63 loc) · 1.73 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"flag"
"fmt"
"os"
"telecomadmin-superman/exp"
"time"
)
func main() {
var (
host string
username string
password string
autoContinue bool
)
flag.StringVar(&host, "host", "192.168.1.1", "光猫地址")
flag.StringVar(&username, "username", "", "普通管理员账号")
flag.StringVar(&password, "password", "", "普通管理员密码")
flag.BoolVar(&autoContinue, "auto-continue", false, "完成后自动退出进程")
flag.Parse()
context := exp.NewContext(host, username, password)
fmt.Printf("- 光猫地址: %s\n", context.GetHost())
suc := false
var result *exp.Result = nil
var err error = nil
allExp := []*exp.Exp{
exp.ALCL_E_140W_P(),
// TODO Add more exp...
}
for _, e := range allExp {
fmt.Printf(" - [%s] 正在尝试...\n", e.Name)
result, err = e.Handle(context)
if err != nil {
fmt.Printf(" - [%s] 失败! %v\n", e.Name, err)
} else {
fmt.Printf(" - [%s] 成功!\n", e.Name)
suc = true
break
}
}
if suc {
fmt.Printf("- 完成!\n")
fmt.Printf(" - 超级管理员账号: %s\n", result.Username)
fmt.Printf(" - 超级管理员密码: %s\n", result.Password)
now := time.Now()
year, mon, day := now.Date()
hour, min, sec := now.Clock()
zone, _ := now.Zone()
configFile := fmt.Sprintf("modem_%04d%02d%02d%02d%02d%02d%s.xml", year, mon, day, hour, min, sec, zone)
err = os.WriteFile(configFile, result.Config, 0644)
if err != nil {
fmt.Printf(" - 写入光猫配置失败! %v\n", err)
} else {
fmt.Printf(" - 光猫配置文件: %s\n", configFile)
}
} else {
fmt.Printf("- 失败, 没有找到适用于你的光猫设备的方案\n")
}
if !autoContinue {
fmt.Printf("- 按回车键退出...\n")
_, _ = fmt.Scanln()
}
}