Code Monkey home page Code Monkey logo

switch-ssh-go's Introduction

switch-ssh-go

A packaged SSH library for switches (huawei,h3c,cisco). A session pool is implemented to avoid repeated connection devices and automatically clear sessions that are not used for 10 minutes.

Installation

$ go get github.com/shenbowei/switch-ssh-go

Basic Usage

In Code

switch-ssh-go implemented a connection pool to save the session, and each session verifies its availability before executing the commands, so you can call the following method repeatedly (not repeatedly connecting the device).

//get the switch brand(vendor), include h3c,huawei and cisco
brand, err := ssh.GetSSHBrand(user, password, ipPort)

//run the cmds in the switch, and get the execution results
result, err := ssh.RunCommands(user, password, ipPort, cmds...)

//run the cmds in the switch with the device brand(the first connection will be faster), and get the execution results
result, err := ssh.RunCommandsWithBrand(user, password, ipPort, ssh.CISCO, cmds...)

example

package main

import (
    "fmt"
    "github.com/shenbowei/switch-ssh-go"
)

func main() {
    user := "your device ssh name"
    password := "your device ssh password"
    ipPort := "ip:22"

    //get the switch brand(vendor), include h3c,huawei and cisco
    brand, err := ssh.GetSSHBrand(user, password, ipPort)
    if err != nil {
        fmt.Println("GetSSHBrand err:\n", err.Error())
    }
    fmt.Println("Device brand is:\n", brand)

    //run the cmds in the switch, and get the execution results
    cmds := make([]string, 0)
    cmds = append(cmds, "dis clock")
    cmds = append(cmds, "dis vlan")
    result, err := ssh.RunCommands(user, password, ipPort, cmds...)
    if err != nil {
        fmt.Println("RunCommands err:\n", err.Error())
    }
    fmt.Println("RunCommands result:\n", result)
}

Licenses

switch-ssh-go is released under the MIT License.

switch-ssh-go's People

Contributors

shenbowei avatar bourbon1991 avatar wangyide avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.