我有一台服务器在网络中的特定端口(WiFi)上运行。在同一端口上的多个IP上可以运行多个服务器。我想知道所有运行服务器的IP。我是初学者。考虑到我想用Java(Android)做这件事,我该怎么办?
答案 0 :(得分:0)
假设您知道所有相关的IP地址:
for (String ipAddress : ipAddresses)
{
try (Socket socket new Socket(ipAddress, port))
{
System.out.println(ipAddress+":"+port+" is listening");
}
catch (IOException exc)
{
System.out.println(ipAddress+":"+port+" connection failure: "+exc);
}
}
E&安培; OE