Can I ssh into Zywall USG310 from c# application ?

Options
DantLucian
DantLucian Posts: 6
Friend Collector First Comment
edited April 2021 in Security
Hello everybody, 
I want to get dhcp-table informations to update my database.
So I want to write an application to get informations from ssh connections.
Is it possible ?
i've tried but the program connect successfully but I can't run or execute commands.
do you have any idea about that ?
Thanks for your response.
Dante

All Replies

  • Zyxel_Vic
    Zyxel_Vic Posts: 281  Zyxel Employee
    First Anniversary 10 Comments Friend Collector First Answer
    Options
    Hi @DantLucian
    Try the command "show ip dhcp binding" in your application after login. This command should popup the leased ip address bindings
  • DantLucian
    Options
    Hi @Zyxel_Vic

    I am not looking for the right command to execute because I can use the "show arp-table" command.
    However I can't execute the command and get the result from C#.
    The thread dedicated to the "runCommand" command of the ssh client, remains on hold and doesn't return any result.
    You will find below an extract of the code executed from a console application on C#.

                using (var client = new SshClient(ipAddressOrHostName, 22, userName, password))
                {
                    client.Connect();
                    if (client.IsConnected)
                    {
                        var cmd = client.CreateCommand("show ip dhcp binding");
                        var asynch = cmd.BeginExecute();
                        // stuck in this loop and doesn't complete
                        while (!asynch.IsCompleted)
                        {
                            // Waiting for command to complete...
                            System.Threading.Thread.Sleep(2000);
                        }
                        var result = cmd.EndExecute(asynch);
                    }
                }

    Do you have an idea of the cause of the problem? 

    Thank you in advance for your answer.
  • Zyxel_Vic
    Zyxel_Vic Posts: 281  Zyxel Employee
    First Anniversary 10 Comments Friend Collector First Answer
    Options
    Hi @DantLucian
    It should be the same on the device systemwise. I can't tell why there're different result when putting different command in your code. Perhaps you can consult some other C# experts.
  • DantLucian
    Options
    Hi @Zyxel_Vic

    The problem does not come from the different commands but from the execution of the "show ip dhcp binding" command which does not finish.
    I manage to execute this command in Telnet but not in ssh.
    Do you have an idea why?
    Have you already realized this case (Execute a command on a USG310 or others from a third party application in ssh) ?
    If yes, which application ?
    If not, is it possible to do it ?
    Did you execute the code I sent you in order to better understand the problem ?

    Thank you in advance for your answer.
  • DantLucian
    Options
    Hi @Zyxel_Vic
    The problem does not come from the different commands but from the execution of the "show ip dhcp binding" command which does not finish.
    I manage to execute this command in Telnet but not in ssh.
    Do you have an idea why?
    Have you already realized this case (Execute a command on a USG310 or others from a third party application in ssh) ?
    If yes, which application ?
    If not, is it possible to do it ?
    Did you execute the code I sent you in order to better understand the problem ?

    Thank you in advance for your answer.
  • Sandra
    Options
    Hi @Zyxel_Vic
    The problem does not come from the different commands but from the execution of the "show ip dhcp binding" command which does not finish.
    I manage to execute this command in Telnet but not in ssh.
    Do you have an idea why?
    Have you already realized this case (Execute a command on a USG310 or others from a third party application in ssh) ?
    If yes, which application ?
    If not, is it possible to do it ?
    Did you execute the code I sent you in order to better understand the problem ?

    Thank you in advance for your answer.
    Agree with you, thinking the same!
  • Ian31
    Ian31 Posts: 174  Master Member
    First Anniversary 10 Comments Friend Collector First Answer
    Options
    I using Python 3.8.2 on Windows 10, with netmiko module.
    Write simple Python script to send command and get output from my ZyWALL110.
    So far, no problem.
    from netmiko import ConnectHandler
    from getpass import getpass

    device1 = { 
        "device_type": "cisco_ios",
        "host": "192.168.168.1",
        "username": "admin",
        "password": getpass(),
        "session_log": "logs.txt"
    }

    # command to execute
    command = "show ip dhcp binding"

    with ConnectHandler(**device1) as net_connect:
        output = net_connect.send_command(command)
  • DantLucian
    Options
    Hi lan31
    It works in python but it doesn't answer my question with C#.
    Thank you for the proposed solution.
    I tested it and it works very well.

  • DantLucian
    DantLucian Posts: 6
    Friend Collector First Comment
    edited March 2021
    Options
    So I think I will close this ticket.

  • kimjonus
    kimjonus Posts: 1
    First Comment
    Options
    usg ssh access denied Nov 14, 2013 · If you need to SSH into an access point ... Step by step procedure You can use the following CLI command to unlock the source IP address via console or SSH.

Security Highlight