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.
65 lines
1.8 KiB
65 lines
1.8 KiB
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os/exec"
|
|
"io/ioutil"
|
|
"strings"
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
upFile = "up-six.sh"
|
|
downFile = "down-six.sh"
|
|
repeatTimer = 120
|
|
)
|
|
|
|
func main() {
|
|
for true {
|
|
fileToExec(downFile)
|
|
fileToExec(upFile)
|
|
time.Sleep(repeatTimer * time.Second)
|
|
}
|
|
}
|
|
|
|
func fileToExec(filename string) {
|
|
doCmds := fileToCmd(filename)
|
|
for _, currCmd := range doCmds {
|
|
actualCmd := ""
|
|
if strings.Count(currCmd, "%x") == 1 {
|
|
actualCmd = fmt.Sprintf(currCmd, rand.Int() % 65536)
|
|
} else if strings.Count(currCmd, "%x") == 2 {
|
|
actualCmd = fmt.Sprintf(currCmd, rand.Int() % 65536, rand.Int() % 65536)
|
|
} else if strings.Count(currCmd, "%x") == 3 {
|
|
actualCmd = fmt.Sprintf(currCmd, rand.Int() % 65536, rand.Int() % 65536, rand.Int() % 65536)
|
|
} else if strings.Count(currCmd, "%x") == 4 {
|
|
actualCmd = fmt.Sprintf(currCmd, rand.Int() % 65536, rand.Int() % 65536, rand.Int() % 65536, rand.Int() % 65536)
|
|
} else if strings.Count(currCmd, "%x") == 5 {
|
|
actualCmd = fmt.Sprintf(currCmd, rand.Int() % 65536, rand.Int() % 65536, rand.Int() % 65536, rand.Int() % 65536, rand.Int() % 65536)
|
|
} else {
|
|
actualCmd = currCmd
|
|
}
|
|
executeCmd(actualCmd)
|
|
}
|
|
}
|
|
|
|
func fileToCmd(filename string) []string {
|
|
fileBody, err := ioutil.ReadFile(filename)
|
|
if err != nil {
|
|
log.Printf("Error while reading file %s\n", filename)
|
|
return []string{}
|
|
}
|
|
cmdArr := strings.Split(string(fileBody), "\n")
|
|
return cmdArr
|
|
}
|
|
|
|
func executeCmd(cmdStr string) {
|
|
cmd := exec.Command("bash", "-c", cmdStr)
|
|
log.Println(cmdStr)
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
}
|