我想实现一个nslookup的功能,先输入nslookup,然后再连续输入多个域名进行查询
现在问题是java的Runtime执行了nslookup之后,CMD窗口就会卡住,没有办法继续往cmd里面发指令
正常的应该如下面:
C:\Documents and Settings\Administrator>nslookup
Default Server: gxdns1.gx.cmcc
Address: 10.185.15.90> www.hao123.com
Server: gxdns1.gx.cmcc
Address: 10.185.15.90Non-authoritative answer:
Name: hao123.n.shifen.com
Address: 123.125.114.174
Aliases: www.hao123.com不知道怎么实现,希望大虾多给点提示
现在问题是java的Runtime执行了nslookup之后,CMD窗口就会卡住,没有办法继续往cmd里面发指令
正常的应该如下面:
C:\Documents and Settings\Administrator>nslookup
Default Server: gxdns1.gx.cmcc
Address: 10.185.15.90> www.hao123.com
Server: gxdns1.gx.cmcc
Address: 10.185.15.90Non-authoritative answer:
Name: hao123.n.shifen.com
Address: 123.125.114.174
Aliases: www.hao123.com不知道怎么实现,希望大虾多给点提示
import java.io.InputStream;public class test {
public test() {
try {
Process p = Runtime.getRuntime().exec(
"cmd /c nslookup www.hao123.com /t:a");
InputStream in = p.getInputStream();
StringBuffer out = new StringBuffer();
byte[] b = new byte[1024];
int n = 0; while ((n = in.read(b)) != -1) {
out.append(new String(b, 0, n));
}
System.out.println(out.toString());
} catch (IOException e) {
e.printStackTrace();
}
} public static void main(String[] args) {
new test();
}
}