1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-24 06:09:01 +08:00
nali/internal/app/command.go

55 lines
1.0 KiB
Go
Raw Normal View History

2020-08-10 13:01:43 +08:00
package app
import (
"bufio"
"fmt"
"os"
2020-08-10 13:29:21 +08:00
"runtime"
2020-08-10 13:01:43 +08:00
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
)
2020-08-10 13:29:21 +08:00
var needTransform = false
2020-08-10 13:01:43 +08:00
func init() {
2020-08-10 13:29:21 +08:00
stat, _ := os.Stdin.Stat()
needTransform = ((stat.Mode() & os.ModeNamedPipe) != 0) && runtime.GOOS == "windows"
2020-08-10 13:01:43 +08:00
}
func Root(args []string) {
if len(args) == 0 {
stdin := bufio.NewScanner(os.Stdin)
for stdin.Scan() {
line := stdin.Text()
2020-08-10 13:29:21 +08:00
if needTransform {
2020-08-10 13:01:43 +08:00
line, _, _ = transform.String(simplifiedchinese.GBK.NewDecoder(), line)
}
if line == "quit" || line == "exit" {
return
}
fmt.Printf("%s\n", ReplaceIPInString(ReplaceCDNInString(line)))
}
} else {
ParseIPs(args)
}
}
func CDN(args []string) {
if len(args) == 0 {
stdin := bufio.NewScanner(os.Stdin)
for stdin.Scan() {
line := stdin.Text()
2020-08-10 13:29:21 +08:00
if needTransform {
2020-08-10 13:01:43 +08:00
line, _, _ = transform.String(simplifiedchinese.GBK.NewDecoder(), line)
}
if line == "quit" || line == "exit" {
return
}
fmt.Println(ReplaceCDNInString(line))
}
} else {
ParseCDNs(args)
}
}