浏览代码

first commit

Sasan Torabkheslat 3 年之前
父节点
当前提交
8a126fa353
共有 6 个文件被更改,包括 98 次插入0 次删除
  1. 8 0
      .idea/.gitignore
  2. 9 0
      .idea/cisco.iml
  3. 3 0
      .idea/dictionaries/sasan.xml
  4. 8 0
      .idea/modules.xml
  5. 二进制
      main
  6. 70 0
      main.go

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 9 - 0
.idea/cisco.iml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="Go" enabled="true" />
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 3 - 0
.idea/dictionaries/sasan.xml

@@ -0,0 +1,3 @@
+<component name="ProjectDictionaryState">
+  <dictionary name="sasan" />
+</component>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/cisco.iml" filepath="$PROJECT_DIR$/.idea/cisco.iml" />
+    </modules>
+  </component>
+</project>

二进制
main


+ 70 - 0
main.go

@@ -0,0 +1,70 @@
+package main
+
+import (
+	"bufio"
+	"bytes"
+	"fmt"
+	"log"
+	"os"
+	"regexp"
+	"strings"
+
+	"golang.org/x/crypto/ssh"
+)
+
+func Connect(user, pass, host string, cmd string) bytes.Buffer {
+	cipher := ssh.Config{
+		Ciphers: []string{"aes128-cbc", "3des-cbc", "aes192-cbc", "aes256-cbc"},
+	}
+	config := &ssh.ClientConfig{
+		User: user,
+		Auth: []ssh.AuthMethod{
+			ssh.Password(pass),
+		},
+		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
+		Config:          cipher,
+	}
+	conn, err := ssh.Dial("tcp", host, config)
+	// time.Sleep(1)
+	if err != nil {
+		log.Fatal("Failed to dial: ", err)
+	}
+	sess, err := conn.NewSession()
+	if err != nil {
+		log.Fatal("Failed to create session: ", err)
+	}
+	stdin, err := sess.StdinPipe()
+	if err != nil {
+		log.Fatal("Failed to create session: ", err)
+	}
+	var bout bytes.Buffer
+	var berr bytes.Buffer
+	sess.Stdout = &bout
+	sess.Stderr = &berr
+	sess.Shell()
+	fmt.Fprintf(stdin, "%s\n", "terminal length 0")
+	fmt.Fprintf(stdin, "%s\n", cmd)
+	fmt.Fprintf(stdin, "\nexit\n")
+	fmt.Fprintf(stdin, "exit\n")
+	sess.Wait()
+	sess.Close()
+	// scanner := bufio.NewScanner(&bout)
+	// for scanner.Scan() {
+	// fmt.Println(scanner.Text())
+	// }
+	// fmt.Println(bout.String())
+	return bout
+}
+func main() {
+
+	result1 := Connect("rancid", "JDACy6wK*yW%meQ", os.Args[1], os.Args[2])
+	scanner := bufio.NewScanner(&result1)
+	for scanner.Scan() {
+		fmt.Println("Text: " + scanner.Text())
+	}
+}
+func IntStringParser(str string) []string {
+
+	re := regexp.MustCompile(`\s{1,}`)
+	return strings.Split(re.ReplaceAllString(str, ","), ",")
+}