📶 [WIP] RouterOS WinBox bruteforce
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mtbf/results.go

70 lines
1.3 KiB

2 years ago
package main
2 years ago
// results.go: saves good results to a file or console
2 years ago
import (
"fmt"
"os"
)
2 years ago
func init() {
registerParam("out-file", "good.txt", "results will be saved in this file")
registerAlias("o", "out-file")
}
2 years ago
var outFile *os.File
2 years ago
var resultChannel chan *Task
func ResultService() {
openResultFile()
defer closeResultFile()
2 years ago
2 years ago
resultChannel = make(chan *Task, 128)
for task := range resultChannel {
2 years ago
if outFile != nil {
2 years ago
fmt.Fprintf(outFile, "%v\n", task.String())
2 years ago
}
2 years ago
}
}
func RegisterResult(task *Task, good bool) {
if !good {
log("res", 1, "bad: %v", task.String())
2 years ago
} else {
2 years ago
log("res", 0, "good: %v", task.String())
if outFile != nil {
resultChannel <- task
}
2 years ago
}
}
2 years ago
func EndResults() {
close(resultChannel)
}
func openResultFile() {
fileName := getParamString("out-file")
2 years ago
if fileName == "" {
log("out", 0, "WARNING: out-file is not specified, results will only be logged in console")
outFile = nil
} else {
var err error
outFile, err = os.OpenFile(fileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
2 years ago
fail("error opening result file \"%v\": %v", fileName, err.Error())
2 years ago
}
2 years ago
log("out", 2, "opened result file \"%v\"", fileName)
2 years ago
}
}
2 years ago
func closeResultFile() {
if outFile != nil {
outFile.Close()
outFile = nil
log("out", 2, "closed result file")
}
2 years ago
}