| |||||||
Das Thema "Ping address" befindet sich unter Android App Entwicklung auf Android-Hilfe.de.
|
| | Themen-Optionen | Ansicht |
| | #1 (permalink) |
| Android Experte Modell: Samsung Galaxy S2 mit CM9 | Asus Transformer Prime Registriert seit: 27.08.2010
Beiträge: 782
Abgegebene Danke: 124
Erhielt 162 Danke für 128 Beiträge
| Ich schreibe im Moment an einem Netzwerkscanner für eine App. Den Scanner hatte ich vorher schon normal mit Java zum Testen implementiert und er lief wunderbar. Dabei rufe ich unter anderem folgende Methode auf: Code: InetAddress.getByName(myIP).isReachable(3000) Code: Tries to reach this InetAddress. This method first tries to use ICMP (ICMP ECHO REQUEST). When first step fails, a TCP connection on port 7 (Echo) of the remote host is established. Code: Test 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. Für diese Info habe ich wirklich viel Zeit in den Sand gesetzt. Ich habe danach meine eigene Methode geschrieben, die funktioniert wunderbar. Wer sich dafür interessiert: Code: private boolean isReachable(String ip) {
try {
Process exec = Runtime.getRuntime().exec("ping " + ip);
BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream()));
reader.readLine();//PING...bytes of data.
String line1 = reader.readLine().trim();
String line2 = reader.readLine().trim();
exec.destroy();
return line1.endsWith("ms") && line2.endsWith("ms");
} catch (IOException e) {
e.printStackTrace();
}
return false;
} Grüße
__________________ Auch ich freue mich, wenn man bei mir den DANKE Button drückt ![]() PowerPoint OpenOffice Remote - Kostenlose App um PowerPoint, OpenOffice und LibreOffice fernzusteuern. Shutdown Remote - Kostenlose App um seinen PC aus der Ferne herunterzufahren. |
| | |
![]() |
|
| Themen-Optionen | |
| Ansicht | |
| |
| ||||
| Thema | Autor | Forum | Antworten | Letzter Beitrag |
| Timeout bei Ping | Jürgen64 | Samsung Galaxy Ace (S5830) Forum | 0 | 19.04.2011 21:04 |
| Alternative zu Youlu Address Book | canada | Sonstige Apps & Widgets | 9 | 24.03.2011 18:52 |
| PING für Android | camou | Kommunikation | 3 | 23.04.2010 11:10 |
| ping für android. | leeno | Kommunikation | 3 | 20.03.2010 19:18 |
| ping für android? | skippe1988 | HTC Magic Forum | 2 | 01.11.2009 11:39 |