cgnet

package module
v0.0.0-...-7d14071 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2023 License: MIT Imports: 10 Imported by: 0

README

Go Reference Go Report Card License

CG - NET

CG-Net is a simple netmiko like package for go to manage cisco devices.

Currently, It's possible to connect to devices using telnet and ssh.

Tested on various cisco catalyst switches, ASRs and ISRs. Other devices should also be possible (:

Installation

go get github.com/Letsu/cgnet

Example

Get Version and configure a loopback interface

package main

import (
	"fmt"
	"github.com/Letsu/cgnet"
)

func main() {
	d := cgnet.Device{
		Ip:       "10.10.10.10",
		Username: "cisco",
		Password: "cisco",
		Enable:   "cisco",
		ConnType: cgnet.SSH,
	}

	err := d.Open()
	defer d.Close()
	if err != nil {
		panic(err)
	}

	ver, err := d.Exec("sh version")
	if err != nil {
		panic(err)
	}
	fmt.Println(ver)

	cmds := []string{"interface loopback10", "ip address 10.10.10.11 255.255.255.255", "no shut"}
	err = d.Configure(cmds)
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownCommand = errors.New("unknown or invalid command")
	ErrAuthFailed     = errors.New("authentication failed")
	ErrNoPrompt       = errors.New("no return of prompt after command")
	ErrUnsupported    = errors.New("unsupported connection type")

	// Timeout for waiting for a prompt
	Timeout = time.Second * 5
	// Log all to stdout of conso
	ShowLog = false

	// Connection types
	Telnet = "telnet"
	SSH    = "ssh"
)

Functions

This section is empty.

Types

type Device

type Device struct {
	Ip         string
	Port       string
	Username   string
	Password   string
	Enable     string
	DeviceType string
	ConnType   string
	// contains filtered or unexported fields
}

func (Device) Close

func (d Device) Close() error

Close the connection to the device

func (Device) Configure

func (d Device) Configure(cmds []string) error

Configure a silce of commands on the device. The commands executed automatically in the 'configure terminal' mode.

func (*Device) Exec

func (d *Device) Exec(cmd ...string) (string, error)

Exec executes a command on the device and returns the output

func (*Device) Exec2

func (d *Device) Exec2(cmd ...string) error

Exec2 executes a command on the device and without returning the output

func (*Device) Open

func (d *Device) Open() error

Open the connection to the device

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL