Skip to content

How to connection cisco router or firewall #379

Closed

Description

@haopxt

I use SSH.NET successful connection to my linux server,but dot not connection to cisco router or firewall,can you give me a example for cisco router,thank you!

Activity

  1. haopxt commented on Jan 26, 2018

    @haopxt
    Author

    using System;
    using Renci.SshNet;
    using System.Text;
    namespace ConsoleApp1
    {
    class Program
    {
    static void Main(string[] args)
    {
    //string ip = "192.168.35.201";
    //string userName = "root";
    //string userPassword = "123456";
    //string command = "ifconfig";
    //ssh_conn_Linux(ip, userName, userPassword, command);

            string ip = "192.168.38.254";
            string userName = "cisco";
            string userPassword = "cisco";
            string enPassword = "cisco123";
            string command = "show run | in route";
            ssh_conn_Network(ip, userName, userPassword, enPassword, command);
    
            Console.ReadKey();
        }
        //Connection Success and response
        public static void ssh_conn_Linux(string ip, string userName, string userPassword, string command)
        {
            StringBuilder result = new StringBuilder();
            var client = new SshClient(ip, userName, userPassword);
            client.Connect();
            result.Append(client.RunCommand(command).Execute() + "\r\n");
            Console.WriteLine(result);
            client.Disconnect();
        }
        //Connection Success,but dot not response
        public static void ssh_conn_Network(string ip, string userName, string userPassword, string enPassword, string command)
        {
            StringBuilder result = new StringBuilder();
            var client = new SshClient(ip, userName, userPassword);
            client.Connect();
            if (client.IsConnected)
            {
                Console.WriteLine("Conn");
                result.Append(client.RunCommand("en").Execute() + "\r\n");
                result.Append(client.RunCommand(enPassword).Execute() + "\r\n");
                result.Append(client.RunCommand(command).Execute() + "\r\n");
                Console.WriteLine(result);
            }
            else
            {
                Console.WriteLine("Dot not conn");
            }
            client.Disconnect();
        }
    }
    

    }

  2. WojciechNagorski commented on Dec 21, 2023

    @WojciechNagorski
    Collaborator

    It's done in #1274

  3. added this to the 2023.0.1 milestone on Dec 21, 2023
  4. WojciechNagorski commented on Dec 29, 2023

    @WojciechNagorski
    Collaborator

    The 2023.0.1 version has been released to Nuget: https://www.nuget.org/packages/SSH.NET/2023.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions