MCPcopy Index your code
hub / github.com/MengMengCode/GetRealityDomain / main

Function main

main.go:45–154  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43}
44
45func main() {
46 // 显示大字标题
47 showTitle()
48
49 // 获取本机IP
50 localIP, err := getLocalIP()
51 if err != nil {
52 printError(fmt.Sprintf("获取本机IP失败: %v", err))
53 localIP = "127.0.0.1" // 默认值
54 }
55
56 // 询问是否使用本机IP
57 useLocalIP := askYesNo(fmt.Sprintf("本机IP为:%s,是否使用该IP?", localIP), true)
58 var targetIP string
59 if useLocalIP {
60 targetIP = localIP
61 } else {
62 fmt.Print("请输入要使用的IP地址: ")
63 targetIP = getStringInput()
64 if net.ParseIP(targetIP) == nil {
65 printError("无效的IP地址格式,使用默认IP")
66 targetIP = localIP
67 }
68 }
69
70 // 询问是否使用/24段
71 use24Subnet := askYesNo("是否使用/24段?", true)
72 var scanTarget string
73 if use24Subnet {
74 scanTarget = targetIP + "/24"
75 } else {
76 fmt.Print("请输入子网掩码位数 (如: /20, /16): ")
77 maskInput := getStringInput()
78 if maskInput == "" {
79 scanTarget = targetIP + "/24"
80 printInfo("使用默认/24段")
81 } else {
82 // 处理用户输入,确保以/开头
83 if !strings.HasPrefix(maskInput, "/") {
84 maskInput = "/" + maskInput
85 }
86
87 // 验证掩码位数是否有效
88 if isValidMask(maskInput) {
89 // 计算网络地址
90 networkAddr, err := calculateNetworkAddress(targetIP, maskInput)
91 if err != nil {
92 printError("计算网络地址失败,使用默认/24段")
93 scanTarget = targetIP + "/24"
94 } else {
95 scanTarget = networkAddr + maskInput
96 printInfo(fmt.Sprintf("计算得到网段: %s", scanTarget))
97 }
98 } else {
99 printError("无效的子网掩码位数,使用默认/24段")
100 scanTarget = targetIP + "/24"
101 }
102 }

Callers

nothing calls this directly

Calls 12

showTitleFunction · 0.85
getLocalIPFunction · 0.85
printErrorFunction · 0.85
askYesNoFunction · 0.85
getStringInputFunction · 0.85
printInfoFunction · 0.85
isValidMaskFunction · 0.85
calculateNetworkAddressFunction · 0.85
clearScreenSystemFunction · 0.85
scanAddressFunction · 0.85
pauseFunction · 0.85
showResultsPaginatedFunction · 0.85

Tested by

no test coverage detected