C#SSH输入指令获取返回值

1.using Renci.SshNet;

2.把Renci.SshNet文件夹移到bin文件夹所在的同一目录

3.将Renci.SshNet.snk文件夹移到bin文件夹所在的同一目录

4.在程序里添加新类,选择Renci.SshNet文件夹下的Renci.SshNet.csproj

5.写方法,如下:

public void aaa()
        {       

            //大多数默认192.168.60.1,后面两个账号密码yyll88xx 
            SshClient sshClient = new SshClient("192.168.60.1", "root", "root"); //建立物件
            sshClient.Connect(); //連線
            string result = "";
            /*創建執行的命令*/
            using (var cmd = sshClient.CreateCommand("l2ping 88:b1:11:fd:17:5d"))
            {
                /*執行後的回傳結果*/
                result = cmd.Execute();
            }

            /*不用後記得斷線*/
            sshClient.Disconnect();
        }

附档包含了程序所需要的文件。

链接:https://pan.baidu.com/s/1m2QWMSxZ3Mh-I-RPRPMB6Q&shfl=sharepset 

 

C#中使用adb指令发送控制指令后,如果界面处于等待输入状态,可以通过持续发送指令获取返回值来实现。以下是一个示例代码,展示了如何在C#中通过adb指令持续发送指令获取返回值: ```csharp using System; using System.Diagnostics; class AdbCommandExecutor { public static string ExecuteAdbCommand(string command) { ProcessStartInfo processStartInfo = new ProcessStartInfo { FileName = "adb", Arguments = command, RedirectStandardOutput = true, RedirectStandardInput = true, UseShellExecute = false, CreateNoWindow = true }; using (Process process = new Process()) { process.StartInfo = processStartInfo; process.Start(); string output = process.StandardOutput.ReadToEnd(); process.WaitForExit(); return output; } } public static void ContinuousSendCommands(string[] commands) { ProcessStartInfo processStartInfo = new ProcessStartInfo { FileName = "adb", Arguments = "", RedirectStandardOutput = true, RedirectStandardInput = true, UseShellExecute = false, CreateNoWindow = true }; using (Process process = new Process()) { process.StartInfo = processStartInfo; process.Start(); foreach (string cmd in commands) { process.StandardInput.WriteLine(cmd); string output = process.StandardOutput.ReadLine(); Console.WriteLine(output); } process.StandardInput.Close(); process.WaitForExit(); } } static void Main(string[] args) { string[] commands = { "input text hello", "input keyevent 4" }; ContinuousSendCommands(commands); } } ``` 在这个示例中,`ExecuteAdbCommand`方法用于执行单个adb命令并返回输出结果。`ContinuousSendCommands`方法用于持续发送一系列命令,并获取每条命令的返回值
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值