当前页面: 开发资料首页 → J2SE 专题 → 想写一个显示本机开放端口的程序~不会写~大家能给点提示么?
想写一个显示本机开放端口的程序~不会写~大家能给点提示么?
摘要: 想写一个显示本机开放端口的程序~不会写~大家能给点提示么?
谢谢
try {
Socket socket = new Socket(ip, port);
if(socket.isConnected()){
System.out.println("端口被占用,连接打开!");
bl = true;
}else{
System.out.println("端口被占用,连接没打开!");
}
bl = true;
socket.close();
socket = null;
} catch (IOException ex) {
ex.printStackTrace();
System.out.println("端口没有使用!");
bl = false;
}
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
/**
*
* @author ronny_zeng
*
*/
public class Exec {
public static void main(String[] args) throws Exception {
Process pro = Runtime.getRuntime().exec("cmd /c netstat -a ");
InputStream is = pro.getInputStream();
byte b;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((b = (byte) is.read()) != -1) {
baos.write(b);
}
System.out.println(baos.toString());
}
}
interpb(曾曾胡,深怕情多累美人!!!)
再写一个不调用系统命令的?
up!..............mark!
up