ERLEDIGT
JA
JA
ANTWORTEN
11
11
ZUGRIFFE
7532
7532
EMPFEHLEN
-
Hi,
ich moechte andere rechner pingen, habe gelesen, dass dies in java nicht moeglich sei. Aber das kann ich nicht glauben
Hat da jemand einen Rat fuer mich?MfG
illaX
-
ich habe den gefunden:
http://www.geocities.com/SiliconVall...index_eng.html
-
04.05.05 10:03 #3
- Registriert seit
- Jun 2002
- Ort
- Saarbrücken (Saarland)
- Beiträge
- 9.886
- Blog-Einträge
- 29
Hallo!
Ein ping mit Java only ist nicht möglich da die dazu notwendigen RAW Sockets zum senden von ICMP Messages nicht unterstützt werden.
http://java.sun.com/j2se/1.5.0/docs/...socketOpt.html
... deshalb muss man hier auf native Komponenten zurückgreifen.
Gruß TomJava rocks!
How to become a good Java Programmer?
Does IT in Java and .Net
The only valid measurement of code quality: WTFs / minute
Blog
Xing
Twitter
-
Vielen Dank fuer eure Antworten.
Ich habe es jetzt mit einer schlechten, aber ausreichenden Methode geloest. Habe die cmd ausgelesen.MfG
illaX
-
04.05.05 13:35 #5
- Registriert seit
- Jun 2002
- Ort
- Saarbrücken (Saarland)
- Beiträge
- 9.886
- Blog-Einträge
- 29
Hallo!
Wie wär's denn damit:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/** * */ 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..."); } } }
Gruß TomJava rocks!
How to become a good Java Programmer?
Does IT in Java and .Net
The only valid measurement of code quality: WTFs / minute
Blog
Xing
Twitter
-
jo tausend dank
ich habe es auch schon mit .getByName ausprobiert, aber ich kam nicht auf .isReachable.
Vielen DankMfG
illaX
-
Aber damit pinge ich doch jetzt oder nicht?
Ich verstehe jetzt nicht mehr, warum alle sagen, dass das mit java nicht moeglich ist.MfG
illaX
-
04.05.05 14:54 #8
- Registriert seit
- Jun 2002
- Ort
- Saarbrücken (Saarland)
- Beiträge
- 9.886
- Blog-Einträge
- 29
Hallo!
Die Methode isReachable an InetAddress gibts auch erst seit Java 5.
gruß Tompublic 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.Java rocks!
How to become a good Java Programmer?
Does IT in Java and .Net
The only valid measurement of code quality: WTFs / minute
Blog
Xing
Twitter
-
Achso schade :'(
Muss ich es doch wieder mit der alten Version machen.MfG
illaX
-
Hi,
ich habe mal ein ähnliches Problem gehabt. Es ging darum zu testen, ob der Inhouse Updateserver verfügbar ist um ggfs. Updates zu laden.
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
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(); }
-
Hallo ich brauch auch einen "Ping" (muss zuminnest wissen ob das gegenüberantwortet)
Mit dem is Reachable klappt es bei Computer relativ gut aber wir haben wir ein Terminal (auch mit IP) und da bekommen ich mit dem isReachable kein True hin.Aber der Ping gibt antworten mit 9ms.
Würde mich um eine schnelle Antwort freuen.
-
nabend,
ich möchte gerne eine Methode programmieren,
die überprüft, ob ein Host online ist oder nicht.
Meine Überlegung
keine "UnknownHostException" --> der DNS-Server ist erreichtbar(return 1)
isReachable liefert true --> Host ist verügbar(return 2)
"else" --> return 0
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/** * Überprüfung des Internetzugangs * return = 0 - Fehler * return = 1 - DNS Name aufgelöst * return = 2 - Host ist reachable */ public static final int checkWeb() { String hosts[] = {"denic.de", "google.com","127.0.0.1"}; InetAddress hostIP; int result = 0; for (int i = 0; i < hosts.length && result < 2; i++) { try { hostIP = InetAddress.getByName(hosts[i]); result = 1; if (hostIP.isReachable(2000)) { result = 2; } } catch (UnknownHostException ex) { //Logger.getLogger(Parser.class.getName()).log(Level.SEVERE, null, ex); result = 0; } catch (IOException ex) { //Logger.getLogger(Parser.class.getName()).log(Level.SEVERE, null, ex); result = 0; } } return result; }
leider ist nur lokalhost erreichbar, und die ersten(externen) urls nicht.
ich nutzte java 1.6.
sieht jemand einen fehler?
Ähnliche Themen
-
Ping an IP
Von flowpow im Forum NetzwerkeAntworten: 2Letzter Beitrag: 30.12.10, 22:32 -
Ping
Von illaX im Forum C/C++Antworten: 10Letzter Beitrag: 30.03.06, 22:51 -
Ping IP
Von Holger_01 im Forum ASPAntworten: 0Letzter Beitrag: 18.05.05, 07:40 -
ms und Ping?
Von DarkManX im Forum Microsoft WindowsAntworten: 0Letzter Beitrag: 13.04.05, 16:45 -
Ping PC1>PC2=ok ABER ping PC2> PC1=fehler
Von Sway im Forum NetzwerkeAntworten: 1Letzter Beitrag: 14.12.03, 23:29





Zitieren

Login





