如何确定线程使用的端口
- 提问者网友:我是我
- 2021-01-29 08:09
- 五星知识达人网友:渊鱼
- 2021-01-29 08:44
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的对应端口 是否有服务