【发布时间】:2019-01-14 23:49:12
【问题描述】:
我可能在这个语法上错了,或者我根本不知道如何执行这个命令。
String ipAddress = request.getRemoteAddr();
System.out.println(ipAddress);
String[] command = {"sudo iptables -t nat -I PREROUTING 1 -s "+ipAddress+" -p tcp -m tcp --dport 80 -j ACCEPT && sudo iptables -t nat -I PREROUTING 2 -s "+ipAddress+" -p tcp -m tcp --dport 443 -j ACCEPT"};
ProcessBuilder probuilder = new ProcessBuilder(command);
Process process = probuilder.start();
//Read out dir output
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:\n",
Arrays.toString(command));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
//Wait to get exit value
try {
int exitValue = process.waitFor();
System.out.println("\n\nExit Value is " + exitValue);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
当有人成功登录我在 Raspberry pi 上运行的 tomcat(localhost) 服务器时,它们是插入 iptables 规则的 2 个命令。在我的 Mac 上它返回一个异常错误,当我尝试在我的手机上成功登录时,它不会让我访问互联网(当我检查 pi 上的 iptables 时没有插入任何内容)。
【问题讨论】: