Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
/**
*
*/
package de.tutorials;
import java.net.InetAddress;
/**
* @author Darimont
*/
public class PingExample {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
String host = "10.23.80.244";
if (InetAddress.getByName(host).isReachable(1000)) {
System.out.println(host + " is reachable...");
} else {
System.out.println(host + " is not reachable...");
}
}
}
public boolean isReachable(int timeout)
throws IOExceptionTest whether that address is reachable. Best effort is made by the implementation to try to reach the host, but firewalls and server configuration may block requests resulting in a unreachable status while some specific ports may be accessible. A typical implementation will use ICMP ECHO REQUESTs if the privilege can be obtained, otherwise it will try to establish a TCP connection on port 7 (Echo) of the destination host.
The timeout value, in milliseconds, indicates the maximum amount of time the try should take. If the operation times out before getting an answer, the host is deemed unreachable. A negative value will result in an IllegalArgumentException being thrown.
SocketAddress sa =null;
InetAddress ia=null;
Socket clientSocket=null;
int inetPort = 0;
try{
URL url = new URL("195.128.56.56");
ia=InetAddress.getByName(url.getHost());
//445 ist der Windows Netzwerkport
sa=new InetSocketAddress(ia,445);
clientSocket=new Socket();
long btime = System.currentTimeMillis();
clientSocket.connect(sa,2500);
clientSocket.close();
long etime = System.currentTimeMillis() - btime;
System.out.println("Zeit ms:"+ etime);
}catch(UnknownHostException uhe){
uhe.printStackTrace();
}catch(SocketTimeoutException stoe){
System.out.println("Ping Exception " + stoe.getMessage());
return false;
}catch(IOException ioe){
ioe.printStackTrace();
}