想写一个显示本机开放端口的程序~不会写~大家能给点提示么? 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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(曾曾胡,深怕情多累美人!!!) 再写一个不调用系统命令的? isInstance,isAssignableFrom两个方法的用法 关于x++,x+=1,x=x+1的效率问题 求一道基础题答案 JAVA解法 java的疑难问题,高手请进 弹出错误对话框界面修改 java中有没有操作符重载? 很简单的问题,我就是想不通 请教一个关于继承的问题 exception:com.ms.security.securityException[host]:cannot access "202.113.189.115":1111? 为什么我的saveFile方法里的BufferWriter老不对 关于javap的使用问题 页面显示效果
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.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()); }
}
再写一个不调用系统命令的?