【发布时间】:2013-06-13 23:14:50
【问题描述】:
我正在尝试在我的机器人上运行 netcat 的 ARM 二进制文件。它已包含在设备上的 data/local/tmp 文件夹中。 netcat 命令也可以通过 adb shell 工作。
但是,我试图从代码中执行命令,netcat 无法正常工作,所以我决定从 ping 之类的基本命令开始。我下面的代码是尝试从手机 ping 我的笔记本电脑。
这同样适用于 adb shell,但似乎不适用于代码。我在wireshark中捕获,运行代码时没有来自手机的数据包。
谁能告诉我为什么 ping 不工作?一旦我修复了那个部分,我就可以转到其他命令。
另外,我尝试了 .waitFor 命令来等待命令运行,但这会在 eclipse 中出现错误。
谢谢
package com.maurice.netcat;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class NetcatActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView text = new TextView(this);
text.setText("Netcat");
setContentView(text);
try
{
String ping = "system/bin/ping -c 1 192.168.0.13";
Runtime.getRuntime().exec(ping);
Toast.makeText(getApplicationContext(), "In Netcat Section", Toast.LENGTH_SHORT).show();
}
catch(IOException e) {
System.out.println("Error Executing Netcat");
Toast.makeText(getApplicationContext(), "In Exception Section", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}
【问题讨论】:
-
我已经在网上关注了很多教程,但它似乎对我不起作用。如果有人有任何建议,我将非常感激。