永发信息网

如何确定线程使用的端口

答案:2  悬赏:30  手机版
解决时间 2021-01-29 12:17
  • 提问者网友:我是我
  • 2021-01-29 08:09
如何确定线程使用的端口
最佳答案
  • 五星知识达人网友:渊鱼
  • 2021-01-29 08:44
netstat 存在于unix/linux/windows
netstat -ao | findstr 8080
可以列出端口号8080对应的PID
另外一个有用的命令,Unix/linux 里用的是lsof, windows 下的procexp 类似lsof, 如果你无法用procexp找不到可以查端口号的话,那么试一下 handle
全部回答
  • 1楼网友:孤独入客枕
  • 2021-01-29 09:19

import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader; import java.net.inetaddress; import java.net.socket; import java.net.unknownhostexception;

public class test {

 public static void main(string args[]) {

  // ip   string host = "120.42.37.88";   // 起始端口   int begin = 137;   // 截止端口   int end = 137;

  if (args.length > 0) {    host = args[0];   }   if (args.length > 1) {    begin = integer.parseint(args[1]);    end = integer.parseint(args[2]);   }

  try {    inetaddress theaddress = inetaddress.getbyname(host);    for (int i = begin; i <= end; i++) {     bufferedreader networkin = null;     try {     socket thesocket = new socket(theaddress, i);     system.out.println("there   is   a   serve   on   port" + i     + "   of   " + host);     networkin = new bufferedreader(new inputstreamreader(     thesocket.getinputstream()));     system.out.println(networkin.readline());     }     catch (ioexception e) {     system.out     .println("there   is   no   service   on   port   "     + i);     }    }// end for   }// end try

  catch (unknownhostexception e) {    system.err.println(e);   }  }// end main

}

检测对于 ip的对应端口 是否有服务 

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯