Tag: 网络扫描

Java网络服务扫描程序

我正在尝试编写一个类,它将扫描本地网络以查找将要运行的服务。 问题是如果地址没有激活(没有回复),它会挂起5秒以上,这是不好的。 我想在几秒钟内完成扫描。 有人可以提供一些建议吗? 我的代码部分如下 int port = 1338; PrintWriter out = null; BufferedReader in = null; for (int i = 1; i < 254; i++){ try { System.out.println(iIPv4+i); Socket kkSocket = null; kkSocket = new Socket(iIPv4+i, port); kkSocket.setKeepAlive(false); kkSocket.setSoTimeout(5); kkSocket.setTcpNoDelay(false); out = new PrintWriter(kkSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream())); out.println("Scanning!"); String fromServer; while […]

查找本地网络中的所有IP地址

我想找到我当前使用Java代码连接到的本地网络中设备的所有IP地址。 有用的实用程序Advanced IP Scanner能够在我的子网 192.168.178/24找到各种IP地址: 根据这个答案,我按以下方式构建了我的代码: import java.io.IOException; import java.net.InetAddress; public class IPScanner { public static void checkHosts(String subnet) throws IOException { int timeout = 100; for (int i = 1; i < 255; i++) { String host = subnet + "." + i; if (InetAddress.getByName(host).isReachable(timeout)) { System.out.println(host + " is reachable"); } } } […]