Esempio n. 1
0
func main() {
	t, err := telnet.Dial("tcp", "10.10.2.209:23")
	checkErr("连接服务器", err)
	t.SetUnixWriteMode(false)

	var data []byte
	typ := "cisco"
	switch typ {
	case "cisco":
		err := expect(t, "ssword: ")
		// checkErr("密码验证", err)

		sendln(t, "cisco")
		err = expect(t, "#")
		checkErr("进入特权模式", err)

		// terminal length 0
		sendln(t, "terminal length 0")

		err = expect(t, "#")
		sendln(t, "show arp")
		checkErr("show arp", err)

		data, err = t.ReadBytes('#')

	default:
		log.Fatalln("bad host type: " + typ)
	}

	os.Stdout.Write(data)
	os.Stdout.WriteString("\n")
}
Esempio n. 2
0
func connectTelnet(config *eqemuconfig.Config) (err error) {
	if t, err = telnet.Dial("tcp", fmt.Sprintf("%s:%s", config.World.Tcp.Ip, config.World.Tcp.Port)); err != nil {
		return
	}
	t.SetReadDeadline(time.Now().Add(10 * time.Second))
	t.SetWriteDeadline(time.Now().Add(10 * time.Second))
	if err = t.SkipUntil("Username:"******"Password:"******"echo off"); err != nil {
		return
	}

	if err = Sendln("acceptmessages on"); err != nil {
		return
	}

	t.SetReadDeadline(time.Time{})
	t.SetWriteDeadline(time.Time{})
	log.Printf("[OOC] Connected\n")
	return
}
Esempio n. 3
0
// Dial creates a new telnet connection. The prompt must be set to the shell
// prompt string.
func Dial(addr, prompt string) (*Conn, error) {
	conn, err := gotelnet.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}
	telnet := &Conn{conn, prompt}
	if err := telnet.waitPrompt(); err != nil {
		return nil, err
	}
	return telnet, err
}
Esempio n. 4
0
// Create a new instance. The port should point to the device's telnet
// CLI port, which appears to usually be 5214.
func NewServerTechPDU(host, port, username, password string) (PDU, error) {
	var tp ServerTechPDU
	conn, err := telnet.Dial("tcp", host+":"+port)
	if err != nil {
		return tp, err
	}
	tp.c = conn
	tp.username = username
	tp.password = password
	return tp, err
}
Esempio n. 5
0
func sendCommand(command string) {
	t, err := telnet.Dial("tcp", "192.168.1.1:23")
	defer t.Close()

	if err != nil {
		log.Fatal(err)
	}
	t.SetUnixWriteMode(true)

	if _, err := t.Write([]byte(command)); err != nil {
		log.Fatal(err)
	}
}
Esempio n. 6
0
// Dial is used to create a TCP Telnet connection to the remote host returning
// only an error if it is unable to dial the remote host.
func (t *TransportTelnet) Dial(target string, username string, password string, vendor VendorIOProc) error {
	if !strings.Contains(target, ":") {
		target = fmt.Sprintf("%s:%d", target, telnetDefaultPort)
	}

	tn, err := telnet.Dial("tcp", target)
	if err != nil {
		return err
	}
	tn.SetUnixWriteMode(true)

	t.telnetConn = tn
	t.ReadWriteCloser = tn
	t.chunkedFraming = false

	vendor.Login(t, username, password)
	vendor.StartNetconf(t)

	return nil
}
Esempio n. 7
0
func main() {
	if len(os.Args) != 3 {
		fmt.Fprintf(os.Stderr, "Usage: %s USER PASSWD\n", os.Args[0])
		return
	}
	user, passwd := os.Args[1], os.Args[2]

	t, err := telnet.Dial("tcp", "127.0.0.1:23")
	checkErr(err)
	t.SetUnixWriteMode(true)

	expect(t, "login: "******"ssword: ")
	sendln(t, passwd)
	expect(t, "$")
	sendln(t, "ls -l")

	ls, err := t.ReadBytes('$')
	checkErr(err)

	os.Stdout.Write(ls)
}
Esempio n. 8
0
func main() {
	if len(os.Args) != 5 {
		log.Printf("Usage: %s {unix|cisco} HOST:PORT USER PASSWD", os.Args[0])
		return
	}
	typ, dst, user, passwd := os.Args[1], os.Args[2], os.Args[3], os.Args[4]

	t, err := telnet.Dial("tcp", dst)
	checkErr(err)
	t.SetUnixWriteMode(true)

	var data []byte
	switch typ {
	case "unix":
		expect(t, "login: "******"ssword: ")
		sendln(t, passwd)
		expect(t, "$")
		sendln(t, "ls -l")
		data, err = t.ReadBytes('$')
	case "cisco":
		expect(t, "name: ")
		sendln(t, user)
		expect(t, "ssword: ")
		sendln(t, passwd)
		expect(t, ">")
		sendln(t, "sh ver")
		data, err = t.ReadBytes('>')
	default:
		log.Fatalln("bad host type: " + typ)
	}
	checkErr(err)
	os.Stdout.Write(data)
	os.Stdout.WriteString("\n")
}