Java语言进行扫描与执行命令


端口/主机扫描器:
Socket socket = new Socket();
SocketAddress address = new InetSocketAddress("192.168.173.1", 3389);
socket.connect(address, 5);
if(socket.isConnected()){System.out.println(3389 + "开放");}
socket.close();
执行CMD命令:
Process process = Runtime.getRuntime().exec("cmd /c " + "netstat -an");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String s = "";
while ((s = in.readLine()) != null) {
    System.out.println(s);
}
process.waitFor();

你可能感兴趣的:(java,扫描)