我想制作一个代码,当移动代理移动到下一个服务器时,如果响应为“OK”,它首先ping服务器,然后移动到下一个服务器。 `
答案 0 :(得分:0)
package in.techdive.java;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class PingApp
{
public static void main(String[] args)
{
String ipAddress = "localhost";
try
{
InetAddress inetadd = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
boolean ipstatus = inetadd.isReachable(10000);
if (ipstatus)
{
System.out.println("Status : Host is reachable");
}
else
{
System.out.println("Status : Host is not reachable");
}
}
catch (UnknownHostException e)
{
System.err.println("Host does not exists");
}
catch (IOException e)
{
System.err.println("Error");
}
}
}
使用此功能可以ping到url并获取状态。希望如果您想要更多帮助通知我,这将对您有所帮助