This is a creation in Article, where the information may have evolved or changed.
Golang SSH host connects to Huawei NE5K router and supports more page breaks
- Using GOLANG/X/CRYPTO/SSH to implement and reference the author: Codyguo code
- Login Huawei Router Execute command display version and display ARP statistics all
- Processing of page breaks generated by the terminal screen width
- Can be used as a single device to carry out the command printout
Key code Description
... in <-"display version"//execute input goroutinein <-"display ARP statistics all" ... go func () {for cmd: = Range in {WG. ADD (1) w.write ([]byte (cmd + "\ n")) WG. Wait ()//control each time Goroutine executes a command}} () go func () {var (buf [1024]byte] t int ) for {n, err: = R.read (buf[t:]) if err! = Nil {fmt. Println (Err. Error ()) close (in) close (out) return} T + = n Result: = String (Buf[:t])//Loop Processing Device page break if strings. Contains (String (Buf[t-n:t]), "more") {W.write ([]byte ("\ n")}//Match the wait to complete an operation to empty Gorouti NE if strings. Contains (Result, "username:") | | Strings. Contains (Result, "Password:") | | Strings. Contains (result, ">") {out <-string (buf[:t]) t = 0 WG.Done ()}}} () ...
Testunit
display versionHuawei Versatile Routing Platform SoftwareVRP (R) software, Version 5.90 (NE40E&80E V600R003C00SPCa00)Copyright (C) 2000-2012 Huawei Technologies Co., Ltd.HUAWEI NE80E uptime is 1695 days, 20 hours, 57 minutesNE80E version information:- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -BKP 1 version information: PCB Version : CR52BKPA REV B MPU Slot Quantity : 2 SRU Slot Quantity : 0 SFU Slot Quantity : 4 LPU Slot Quantity : 16.........<HK-HK-CW-F-1.CN2>display arp statistics allDynamic: 345 Static: 0 <HK-HK-CW-F-1.CN2>