Golang SSH host connects to Huawei NE5K router and supports more page breaks

Source: Internet
Author: User
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.