├── .classpath
├── .gitignore
├── .project
├── AndroidManifest.xml
├── README.md
├── build.properties
├── build.xml
├── default.properties
├── gpl-2.0.txt
├── libs
└── org.apache.http.legacy.jar
├── local.properties-example
├── res
├── drawable-hdpi
│ └── icon.png
├── drawable-ldpi
│ └── icon.png
├── drawable-mdpi
│ └── icon.png
├── drawable
│ ├── arrow_right.png
│ ├── back.png
│ ├── btn_bg.xml
│ ├── btn_donate.png
│ ├── cancel.png
│ ├── closed.png
│ ├── computer.png
│ ├── computer_down.png
│ ├── connect.png
│ ├── disabled.png
│ ├── discover.png
│ ├── drawer_bg.xml
│ ├── export.png
│ ├── icon.png
│ ├── install.png
│ ├── open.png
│ ├── router.png
│ ├── settings.png
│ └── wifi.png
├── layout-land
│ └── portscan.xml
├── layout
│ ├── dialog_edittext.xml
│ ├── discovery.xml
│ ├── help.xml
│ ├── list_host.xml
│ ├── list_port.xml
│ ├── main.xml
│ ├── portscan.xml
│ └── scan_single.xml
├── raw
│ ├── saves.bin
│ └── services.bin
├── values-de
│ └── strings.xml
├── values-es
│ └── strings.xml
├── values-fr
│ └── strings.xml
├── values-zh-rCN
│ └── strings.xml
├── values-zh-rTW
│ └── strings.xml
├── values
│ ├── arrays.xml
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
└── xml
│ └── preferences.xml
├── scripts
├── create-nic-db.py
├── create-probes-db.py
├── create-services-db.py
└── make-native.sh
└── src
└── info
└── lamatricexiste
└── network
├── AbstractDiscovery.java
├── ActivityDiscovery.java
├── ActivityMain.java
├── ActivityNet.java
├── ActivityPortscan.java
├── AsyncPortscan.java
├── DefaultDiscovery.java
├── DnsDiscovery.java
├── Network
├── Banner.java
├── DownloadFile.java
├── HardwareAddress.java
├── HostBean.java
├── NetInfo.java
├── OsFingerprint.java
├── Ping.java
├── RateControl.java
└── SendSmbNegotiate.java
└── Utils
├── Db.java
├── DbUpdate.java
├── Export.java
├── Help.java
├── Prefs.java
├── Save.java
└── UpdateNicDb.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | gen
2 | bin
3 | .settings
4 | network.kpf
5 | scripts/db-to-gz.py
6 | local.properties
7 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | NetworkDiscovery
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
12 |
13 |
17 |
18 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
32 |
33 |
37 |
38 |
39 |
40 |
48 |
49 |
50 |
51 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Network Discovery
2 | =================
3 |
4 | Machines discovery/mapping (over Wifi) and port scan (over 3G/Wifi) utility for Android devices.
5 |
6 | Features
7 | --------
8 |
9 | - Discover Machines on a LAN (connect/ping discovery, dns discovery)
10 | - TCP Port Scanner (connect() scan)
11 | - NIC vendor database
12 | - Export results to your sdcard in XML
13 | - Fast access to Wifi Settings
14 | - Adaptive scanning rate (slow start, then adaptive to network latency)
15 | - Open Source, available at http://github.com/rorist/android-network-discovery
16 |
17 | Build
18 | -----
19 | git clone https://github.com/rorist/android-network-discovery.git
20 | cd android-network-discovery;
21 | cp local.properties-example local.properties
22 | vim local.properties #add path to the Android SDK
23 | ant debug install
24 |
25 | Todo
26 | ----
27 |
28 | - Save all scan in DB, open previous scan, export previous scan, etc
29 | - Settings: prevent phone from sleeping
30 | - NMAP build script (ARM and other arch (using AOSP?))
31 | - Add new info such as Hops (using MTR?)
32 | - Support of other protocol: UDP, SCTP
33 | - Send custom packets (shell codes, exploits, probes, ...)
34 | - Nat Traversal
35 | - Proxy (auto)support
36 |
37 | Credits
38 | ------
39 |
40 | - Design: oblivioncreations.se
41 | - Icons: Crystal and Oxygen projects
42 | - German translation, bugfixes: SubOptimal
43 | - Spanish translation: ghiki
44 | - Chinese translation: goapk.com
45 |
46 | GPLv2 License
47 | -------
48 |
49 | Copyright (C) 2009-2011 Aubort Jean-Baptiste (Rorist)
50 |
51 | This program is free software; you can redistribute it and/or
52 | modify it under the terms of the GNU General Public License
53 | as published by the Free Software Foundation; either version 2
54 | of the License, or (at your option) any later version.
55 |
56 | This program is distributed in the hope that it will be useful,
57 | but WITHOUT ANY WARRANTY; without even the implied warranty of
58 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59 | GNU General Public License for more details.
60 |
61 | You should have received a copy of the GNU General Public License
62 | along with this program; if not, write to the Free Software
63 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
64 |
65 | Copy of the license can be found in gpl-2.0.txt
66 |
67 |
--------------------------------------------------------------------------------
/build.properties:
--------------------------------------------------------------------------------
1 | # This file is used to override default values used by the Ant build system.
2 |
3 | # The name of your application package as defined in the manifest.
4 | # Used by the 'uninstall' rule.
5 | application-package=info.lamatricexiste.network
6 |
7 | # The name of the source folder.
8 | source-folder=src
9 |
10 | # The name of the output folder.
11 | out-folder=bin
12 |
13 | jar.libs.dir=libs
14 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/default.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Indicates whether an apk should be generated for each density.
11 | split.density=false
12 | # Project target.
13 | target=android-26
14 |
--------------------------------------------------------------------------------
/libs/org.apache.http.legacy.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/libs/org.apache.http.legacy.jar
--------------------------------------------------------------------------------
/local.properties-example:
--------------------------------------------------------------------------------
1 | sdk-location=/opt/android-sdk
2 | sdk.dir=/opt/android-sdk
3 | target=android-26
4 |
5 | key.store=/home//.android/my-release-key.keystore
6 | key.alias=
7 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/res/drawable/arrow_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/arrow_right.png
--------------------------------------------------------------------------------
/res/drawable/back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/back.png
--------------------------------------------------------------------------------
/res/drawable/btn_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
8 | -
10 |
11 |
15 |
18 |
20 |
21 |
22 | -
24 |
25 |
29 |
32 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/res/drawable/btn_donate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/btn_donate.png
--------------------------------------------------------------------------------
/res/drawable/cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/cancel.png
--------------------------------------------------------------------------------
/res/drawable/closed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/closed.png
--------------------------------------------------------------------------------
/res/drawable/computer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/computer.png
--------------------------------------------------------------------------------
/res/drawable/computer_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/computer_down.png
--------------------------------------------------------------------------------
/res/drawable/connect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/connect.png
--------------------------------------------------------------------------------
/res/drawable/disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/disabled.png
--------------------------------------------------------------------------------
/res/drawable/discover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/discover.png
--------------------------------------------------------------------------------
/res/drawable/drawer_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/res/drawable/export.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/export.png
--------------------------------------------------------------------------------
/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/icon.png
--------------------------------------------------------------------------------
/res/drawable/install.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/install.png
--------------------------------------------------------------------------------
/res/drawable/open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/open.png
--------------------------------------------------------------------------------
/res/drawable/router.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/router.png
--------------------------------------------------------------------------------
/res/drawable/settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/settings.png
--------------------------------------------------------------------------------
/res/drawable/wifi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/drawable/wifi.png
--------------------------------------------------------------------------------
/res/layout-land/portscan.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
14 |
21 |
29 |
44 |
53 |
61 |
70 |
79 |
80 |
85 |
91 |
95 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/res/layout/dialog_edittext.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
17 |
18 |
--------------------------------------------------------------------------------
/res/layout/discovery.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
13 |
18 |
23 |
28 |
29 |
33 |
39 |
93 |
94 |
104 |
110 |
117 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/res/layout/help.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
9 |
10 |
15 |
16 |
22 |
23 |
28 |
33 |
34 |
39 |
44 |
45 |
50 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/res/layout/list_host.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
12 |
13 |
14 |
22 |
23 |
30 |
31 |
39 |
40 |
46 |
47 |
55 |
56 |
57 |
58 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/res/layout/list_port.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
14 |
15 |
22 |
23 |
28 |
29 |
35 |
36 |
37 |
38 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
11 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/res/layout/portscan.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
14 |
21 |
29 |
42 |
50 |
60 |
61 |
66 |
72 |
76 |
80 |
81 |
86 |
95 |
104 |
105 |
106 |
107 |
--------------------------------------------------------------------------------
/res/layout/scan_single.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
11 |
18 |
26 |
27 |
--------------------------------------------------------------------------------
/res/raw/saves.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/raw/saves.bin
--------------------------------------------------------------------------------
/res/raw/services.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rorist/android-network-discovery/a64b8a6018fddabd7d8d94fd97f899b1cd8e8d80/res/raw/services.bin
--------------------------------------------------------------------------------
/res/values-de/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 | Network Discovery
8 | Lade
9 | Ja
10 | Nein
11 | Ok
12 | Suche
13 | Abbrechen
14 | Export
15 | Schließen
16 | Scannen
17 | Einstellungen
18 | Zurück
19 | Info
20 | Ports
21 | Entferne
22 |
23 | Herunterladen und installieren von Datenbank \'%s\'...
24 | Erstelle Dienste-Datenbank...\nDas dauert einen kurzen Moment...
25 |
26 | %s muss über den Market installiert werden!
27 |
28 | WLAN ist aktiviert
29 | WLAN wird aktiviert
30 | WLAN wird deaktiviert
31 | WLAN ist deaktiviert
32 | scanne WLAN
33 | WLAN ist verbunden mit %s
34 | Erhalte IP-Adresse von %s
35 | WLAN Status ist unbekannt
36 |
37 | IP: %1$s/%2$d (%3$s)
38 | Betreiber: %s
39 | SSID: %s
40 | MODUS: %s
41 | WLAN (%1$s %2$s)
42 | Mobil
43 | Ethernet (noch nicht unterstützt)
44 | Unbekannt
45 |
46 | Suche gestartet...
47 | Suche abgeschlossen!
48 | Suche abgebrochen!
49 | Proxy-Fehler
50 | Suche wurde abgebrochen, da eine MAC-Addresse mehrfach gefunden wurde. Du befindest Dich vermutlich hinter einem Proxy.\n\nGehe zum Gateway über den Browser: http://%s
51 | Installation: Root
52 | Möchtest Du den scan Dämon für den User root installieren?
53 | Neustart der Anwendung...
54 | Drücke auf \'Suche\' zum starten
55 | Aktion wählen
56 | Scanne Ports
57 | Ändere Namen
58 | Name gespeichert!
59 | Name gelöscht!
60 | MyPhone
61 |
62 | Scanne IP
63 | Eine IP-Adresse oder einen FQDN zum Scannen eingeben, z.b. scanme.nmap.org
64 | Keine offenen Ports gefunden!
65 | Keine Aktion festgelegt!
66 | Verbinde
67 | Suche gestartet...
68 | Suche abgeschlossen!
69 | Suche abgebrochen!
70 | Offen (%s)
71 | Geschlossen (%s)
72 | Host nicht erreichbar!
73 | Port %s/tcp
74 |
75 | Antwortzeit:
76 | MAC-Adresse:
77 | NIC Hersteller:
78 | Offene Ports:
79 | Geschlossene Ports:
80 | Unbekannt
81 |
82 | Datei gespeichert!
83 | Zielverzeichnis wählen
84 | Speichern
85 | Datei existiert bereits
86 | Möchtest Du die Datei überschreiben?
87 |
88 | Host Suche
89 | Die gewählte Methode benötigt keine root Berechtigungen. In zukünftigen Versionen wird es verbesserte Techniken geben, nachdem die Nicht-Root Techniken verfeinert wurden.\n\nKurzanleitung wie es funktioniert: \n1. Größe des Subnetzes ermitteln\n2. Wiederhole für jede IP-Adresse\n3. zuerst ein ICMP Ping oder Echo auf TCP Port 7 senden (mittels InetAddress.isReachable())\n4. funktioniert das nicht, wird versucht eine TCP-Verbindung über Ports von Standarddiensten herzustellen, wie z.B. 135, 139, 22, 111, 80\n5. ist keiner dieser Versuche erfolgreich, wird der entsprechende Hostrechner nicht erkannt
90 | Portscan
91 | Der Portscan ist Event gesteuert, unter Verwendung der Java Klassen Selector und SocketChannel.\nDer Timeout wird simuliert, indem beim Erstellen des Sockets die Zeit in Millisekunden ermittelt wird und dieser Wert anschliessend wiederholt geprüft wird.\nDie Portscanmethode, während der Suche, basiert auf einer erfolgreichen TCP-Verbindung. (In zukünftigen Versionen, mit root Berechtigungen, wird es feinere Abstufungen geben.)\n\nMaximal 127 Sockets sind gleichzeitig geöffnet. Das ist nicht immer präzise, aber recht schnell. Auch hier wird es eine neue Funktion geben, welche die Zeit zwischen den Anfragen abhängig von der Antwortverzögerung des Hostrechners festlegt (eine Art softwaregesteuerter Netzwerküberlastungskontrolle)\n\nDer Zustand eines Ports wird wie folgt ausgegeben:\noffen - wenn eine TCP-Verbindung erfolgreich hergstellt wurde\ngeschlossen - wenn kein Dienst die Anfrage beantwortet\ngefiltert - wenn es zu einem Timeout kommt
92 | Links
93 | - TCP Connect Scan: http://nmap.org/book/man-port-scanning-techniques.html#id421401\n\n- Host Discovery: http://nmap.org/book/man-host-discovery.html
94 |
95 | Hilfe
96 | Exportieren
97 | Danksagung
98 | Netzwerk-Suche
99 | Portscan
100 | Allgemein
101 |
102 | Ermittle Hostnamen
103 | Verwende DNS um IP-Adressen aufzulösen
104 | Vibrieren
105 | Vibriere wenn die Suche beendet wurde
106 | Timeout
107 | Aktiviere automatische Erkennung von Timeouts
108 | Zeit für Timeout
109 | Timeout nach x Millisekunden
110 | Erster Port
111 | Erster zu scannender TCP Port. 1-65535
112 | Letzter Port
113 | Letzter zu scannender TCP Port. 1-65535
114 | Dienste Banner
115 | Liest Banner bei verbundenen Sockets (z.B.: SSH-2.0-OpenSSH_5.1p1)
116 | Timeout festlegen
117 | Verbindungstimeout manuell festlegen
118 | Verbindungstimeout
119 | Verbindungstimeout über einen Port, in Millisekunden
120 | Erlaube Suche über Mobilnetz
121 | Scannen über Edge/3G/... liefert, wenn überhaupt, meist seltsame Ergebnisse
122 | SSH Benutzername
123 | Benutzername für die SSH Verbindung
124 | Threadpool
125 | maximale Anzahl von Threads während des Host-Suche (1-256)
126 | Aktualisiere NIC-Datenbank
127 | Hole und aktualisiere MAC-Adressen-Datenbank
128 | Soll die Datei \'%1$s\' heruntergeladen werden? (~%2$sk)
129 | Datenbank aktualisiert! %s neue Einträge...
130 | Version
131 | Webseite
132 | Kontakt
133 | Netzwerkschnittstelle
134 | Wähle die zu verwendende Schnittstelle aus
135 | Erkennungsmethode
136 | eine andere Host-Erkennungsmethode wählen
137 | Erkennungsmethode wählen
138 | erste IP-Adresse
139 | Erste zu scannende IP-Adresse
140 | letzte IP-Adresse
141 | Letzte zu scannende IP-Adresse
142 | IP Bereich festlegen
143 | Start-/End-IP manuell angeben
144 | CIDR festlegen
145 | setze CIDR manuell (definiert das Subnetz)
146 | Ändere CIDR
147 |
148 | Fehler: Erste ist größer als Letzte!
149 | Fehler: Anzahl der Threads muss zwischen 1 und 256 liegen!
150 | Fehler: Dateiübertragung unterbrochen!
151 | Fehler: Die Eingabe ist keine gültige IP-Adresse!
152 |
153 |
154 | - Ping/Connect (Standard)
155 | - DNS Abfrage
156 |
157 | Einstellungen
158 |
159 |
160 |
--------------------------------------------------------------------------------
/res/values-es/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 | Network Discovery
9 | Cargando
10 | Si
11 | No
12 | Ok
13 | Descubrir
14 | Cancelar
15 | Exportar
16 | Cerrar
17 | Escanear
18 | Opciones
19 | Atras
20 | Info
21 | Puertos
22 | Eliminar
23 |
24 | Descargando y instalando la base de datos %s ...
25 | Creando base de datos de servicios...\nEsto puede tardar un poco...
26 |
27 | %s necesita ser instalado desde el Market!
28 |
29 | El WiFi está activado
30 | El WiFi se está activando
31 | El WiFi se está desactivando
32 | El WiFi está desactivado
33 | El WiFi está escaneando
34 | El WiFi se está asocuando con %s
35 | Obteniendo dirección IP de %s
36 | Estado de WiFi desconocido
37 |
38 | IP: %1$s/%2$d (%3$s)
39 | PROVEEDOR: %s
40 | SSID: %s
41 | MODO: %s
42 | WiFi (%1$s %2$s)
43 | Movil
44 | Ethernet (No soportado aún)
45 | Desconocido
46 |
47 | Descubrimiento iniciado...
48 | Descubrimiento terminado!
49 | Descubrimiento cancelado!
50 | Error de Proxy
51 | El descubrimiento ha sido cancelado porque una dirección MAC ha aparecido en múltiples ocasiones, probablemente se encuentre detrás de un proxy.\n\nvaya a su Puerta de Enlace desde su navegador : http://%s
52 | Instalacion: Root
53 | Quiere instalar el demonio de escaneo para root?
54 | Reiniciando aplicación...
55 | Pulse "Descubrir" para empezar
56 | Elija una acción
57 | Escanear puertos
58 | Cambiar nombre
59 | Nombre guardado!
60 | Nombre borrado!
61 | MiTelefono
62 |
63 | Escanear IP
64 | Introduzca una dirección IP o FQDN para escanear, p.ej. scanme.nmap.org
65 | Ningún puerto abierto encontrado!
66 | Ninguna acción asociada!
67 | Conectar
68 | Escaneo iniciado...
69 | Escaneo terminado!
70 | Escaneo cancelado!
71 | Abierto (%s)
72 | Cerrado (%s)
73 | Host inaccesible!
74 | Puerto %s/tcp
75 |
76 | Tiempo de respuesta:
77 | Dirección MAC:
78 | Proveedor NIC:
79 | Puertos abiertos:
80 | Puertos cerrados:
81 | Desconocido
82 |
83 | Archivo guardado!
84 | Seleccione destino de archivo
85 | Guardar
86 | El archivo ya existe
87 | Quiere sobrescribirlo?
88 |
89 | Descubrimiento de Hosts
90 | El método que se utiliza, no necesita tener privilegios de root. En futuras versiones habrá técnicas más avanzadas, una vez que los root estén pulidos.\n\nAquie está su funcionamiento: \n1. Calcula el rango de subred\n2. Iterar a través de IP y consultarlos\n3. En primer lugar, envía un ping ICMP echo a tcp/7 (mediante InetAddress.isReachable())\n4. Si esto no funciona, prueba a conectar() en puertos conocidos, como: 135, 139, 22, 111, 80\n5. Si nada de lo anterior funciona, el host no se descubrirá
91 | Escaner de puertos
92 | El escaneo de puertos está orientado a eventos, usando el "Selector" de Java y "SocketChannel".\nHay un tiempo de espera de falso al registrar el tiempo en ms en la creación de sockets y comprobar regularmente este valor.\nEl método de escaneo de puertos, como el descubrimiento, utiliza comprobación completa de conexión TCP. (será más detallado en el futuro con características de usuario root.)\n\nUn máximo de 127 sockets son abiertos a la vez, así que esto no siempre es preciso, pero es bastante rápido. Una vez más, una nueva característica está llegando que será adaptar los tiempos entre las solicitudes para organizarlas según el tiempo de respuesta (tipo de software de control de congestión de la red)\n\nUn puerto se considera abierto cuando tcp connect() se efectúa correctamente, cerrado cuando no hay servicio de escucha en el otro extremo, o filtrado cuando el tiempo límite se alcance.
93 | Links
94 | - Escaneo TCP connect: http://nmap.org/book/man-port-scanning-techniques.html#id421401\n\n- Host discovery: http://nmap.org/book/man-host-discovery.html
95 |
96 | Ayuda
97 | Exportar
98 | Créditos
99 | Descubrimiento
100 | Escaner de puertos
101 | General
102 |
103 | Resolver Hostname
104 | Usar DNS del sistema para resolver direcciones IP
105 | Vibrar
106 | Vibrar cuando el Escaneo se haya completado
107 | Control de velocidad
108 | Activar la detección automática de velocidad
109 | Velocidad personalizada
110 | Velocidad de descubrimiento en milisegundos
111 | Primer puerto
112 | Primer puerto TCP a escanear. 1-65535
113 | Último puerto
114 | Último puerto TCP a escanear. 1-65535
115 | Banners de servicios
116 | Leer banner desde un socket conectado (ex.: SSH-2.0-OpenSSH_5.1p1)
117 | Tiempo de espera personalizado
118 | Configurar manualmente tiempo de espera de connect
119 | Tiempo de espera de connect
120 | Tiempo de espera de una conexión a un puerto en milisegundos
121 | Permitir la detección móvil
122 | Escanear a través de EDGE/3G ... por lo general conduce a resultados extraños, si hay alguno
123 | Usuario SSH
124 | Usuario para la conexión SSH
125 | Subprocesos
126 | Número máximo de subprocesos a utilizar en el descubrimiento de hosts (1-256)
127 | Actualizar base de datos NIC
128 | Vaciar y actualizar la base de datos las direcciones MAC
129 | Quiere descargar %1$s ? (~%2$sk)
130 | base de datos actualizada! %s entradas nuevas...
131 | Versión
132 | Página Web
133 | Contacto
134 | Interfaz de red
135 | Seleccione la interfaz a usar
136 | Método de descubrimiento
137 | Cambiar el método de descubrimiento de hosts
138 | Seleccione un método
139 | Primera IP
140 | Primera dirección IP a escanear
141 | Última IP
142 | Última dirección IP a escanear
143 | Rango de direcciones IP personalizadas
144 | Configurar manualmente primera/última IP
145 | CIDR personalizado
146 | Configurar el CIDR manualmente (define la subred)
147 | Cambiar CIDR
148 |
149 | Error: El primero es mayor que el último!
150 | Error: El número de subprocesos debe ser entre 1 y 256!
151 | Error: Transferencia de archivos interrumpida!
152 | Error: El valor no es una dirección IP válida!
153 |
154 |
155 | - Ping/connect (default)
156 | - DNS requests
157 |
158 |
159 |
160 |
--------------------------------------------------------------------------------
/res/values-fr/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 | Network Discovery
8 | Chargement
9 | Oui
10 | Non
11 | Rechercher
12 | Annuler
13 | Exporter
14 | Fermer
15 | Scanner
16 | Options
17 | Retour
18 | Info
19 | Ports
20 |
21 | Téléchargement de la base %s ...
22 | Création de la base de données des Services ... Veuillez patienter ...
23 |
24 | %s doit être installée depuis le Market !
25 |
26 | Wifi activé
27 | Wifi en cours d\'activation
28 | Wifi en cours de desactivation
29 | Wifi desactivé
30 | Recherche des réseaux wifi
31 | Association en cours avec %s
32 | Demande d\'adresse IP à %s
33 | Etat du Wifi inconnu
34 |
35 | Recherche démarrée ...
36 | Recherche terminée !
37 | Recherche annulée !
38 | Erreur proxy
39 | La recherche est annulée car une adresse mac est apparue plusieurs fois, vous êtes probablement derrière un proxy.\n\nAccédez à la passerelle depuis votre navigateur: http://%s
40 | Installation: Root
41 | Voulez-vous installer le service de scan en root ?
42 | Redémarrage de l\'application ...
43 | Appuyez sur Rechercher pour démarrer
44 |
45 | Scanner une IP
46 | Entrez une adresse IP ou un nom d\'hôte sur lequel effectuer un scan de ports, p.ex. scanme.nmap.org
47 | Aucun port trouvé !
48 | Aucune action associée !
49 | Ouvrir
50 | Scan démarré ...
51 | Scan terminé !
52 | Scan annulé !
53 | Ouvert (%s)
54 | Fermé (%s)
55 | L\'hôte n\'est pas atteignable !
56 |
57 | Temps de réponse:
58 | Adresse MAC:
59 | Vendeur NIC:
60 | Ports ouverts:
61 | Ports fermés:
62 | Inconnu
63 |
64 | Fichier sauvegardé !
65 | Choisir la destination
66 | Sauver
67 | Le fichier existe déjà
68 | Voulez-vous l\'écraser ?
69 |
70 | Découverte de machines
71 | La méthode utilisé, ne requiert pas les privilèges root. Dans les versions futures, des techniques plus avancées seront utilisée, une fois que l\'aspect non-root fonctionnera bien.\n\nVoici comment cela fonctionne:\n1. Calcule de la plage d\'IP du sous-réseau\n2. Iteration sur les adresses IP et lance une requête\n3. D\'abord cela execute la méthode InetAddress.isReachable(), qui lance un ping ICMP ou un Echo sur le port tcp/7\n4. Puis si cela n\'aboutit pas, on essaie de se connecter sur des ports connus (tcp connect()) tels que: 135, 139, 22, 111, 80\n5. Si aucune des méthodes n\'aboutit, la machine n\'est pas découverte
72 | Scan de ports
73 | Le scan de ports est orienté évènements, en utilisant les Selector et SocketChannel de Java.\nLe timeout est simulé en enregistrant le temps en ms lors de la création du socket et en vérifiant régulérement cette valeur.\n\nLa méthode de scan, tout comme pour la découverte de machine, utilise une connection tcp complète. (d\'autres méthodes de scan arriveront avec les fonctionnalités root)\nUn maximum de 127 sockets sont ouverts en même temps, la méthode n\'est donc pas toujours précise, mais relativement rapide.\nCela sera amélioré notement grâce à une future méthode de vérification de la congestion du réseau, se basant sur les temps de réponse des machines.\n\nUn port est consideré ouvert lorsque la connection tcp est complète, fermé lorsque la connection est établie mais qu\'aucun service n\'est actif sur le port et filtré après que le timeout soit écoulé.
74 | Liens
75 | - Méthodes de scan de ports de Nmap: http://nmap.org/man/fr/man-port-scanning-techniques.html\n\n- Découverte de machines dans nmap: http://nmap.org/man/fr/man-host-discovery.html
76 |
77 | Aide
78 | Exporter
79 | Credits
80 | Découverte de Machines
81 | Scan de Ports
82 | Général
83 |
84 | Résoudre les noms d\'hôtes
85 | Utiliser la résolution DNS du système pour résoudre les IP
86 | Vibration
87 | Vibre lorsque le Scan est terminé
88 | Contrôle fréquence de scan
89 | Activer le contôle automatique de la vitesse de scan
90 | Délai de connection
91 | Délai maximum d\'une connection à une machine, en millisecondes
92 | Premier port
93 | Le premier port TCP à scanner. 1-65535
94 | Dernier port
95 | Le dernier port TCP à scanner. 1-65535
96 | Bannière de services
97 | Lit la banière pour un connection établie. (ex.: SSH-2.0-OpenSSH_5.1p1)
98 | Délai de connection personnalisé
99 | Régler manuellement le délai de connection
100 | Délai de connection
101 | Délai maximum d\'une connection à un port, en millisecondes
102 | Scan par 3G
103 | Permet de scanner le réseau 3g/edge, résultats peuvent être inattendus
104 | Nom d\'utilisateur SSH
105 | Utilisateur à utiliser pour se connecter en SSH
106 | Threads
107 | Nombre maximum de threads à utiliser lors de la découverte de machines (1-256)
108 | Mettre à jour la base des NIC
109 | Syncroniser la base des adresses MAC et des constructeurs de NIC
110 | Voulez-vous télécharger la BDD ? (~%sk)
111 | Base de donnée mise à jour ! %S nouveaux éléments ...
112 | Version
113 | Site internet
114 | Contact
115 | Interface réseau
116 | Choix de l\'interface à utiliser
117 | Méthode de découverte
118 | Changer la méthode de découverte des machines
119 | Choisissez une méthode
120 | IP début
121 | Première adresse IP à scanner
122 | IP fin
123 | Dernière adresse IP à scanner
124 | Plage d\'adresse IP personnalisée
125 |
126 |
127 | Erreur: Le premier est plus grand que le dernier.
128 | Erreur: Le nombre de Threads doit être entre 1 et 256 !
129 | Erreur: Le téléchargement du fichier a été interrompu !
130 | Erreur: La valeur n\'est pas une adresse IP valide !
131 |
132 |
133 | - Ping/connect (défaut)
134 | - Requêtes DNS
135 |
136 |
137 |
138 |
--------------------------------------------------------------------------------
/res/values-zh-rCN/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 | Network Discovery
8 | 加载中
9 | 是
10 | 否
11 | 发掘
12 | 取消
13 | 导出
14 | 关闭
15 | 扫描
16 | 选项
17 | 返回
18 | 信息
19 | 港口
20 |
21 | 必须从市场上安装 %s !
22 |
23 | Wifi 已开启
24 | Wifi 启用中
25 | Wifi 关闭中
26 | Wifi 已关闭
27 | Wifi 扫描中
28 | Wifi是用 %s 联入的
29 | 正在从 %s 获取IP地址
30 | Wifi 状态未知
31 |
32 | 开始发掘 ...
33 | 发掘完成!
34 | 已取消发掘!
35 | 代理错误
36 | 发掘已被取消,由于一个MAC地址出现了多次,您可能是在一个代理环境下。\n\n从浏览器转到您的网关:http://%s
37 | 安装: Root
38 | 是否需要以ROOT权限安装后台扫描程序?
39 | 程序重启中 ...
40 | Press Discover to start
41 |
42 | 扫描 IP
43 | 输入一个IP地址或者域名以供扫描,例如 scanme.nmap.org
44 | 未发现打开的端口!
45 | 无相关操作!
46 | 连接
47 | 开始扫描 ...
48 | 扫描完成!
49 | 已取消扫描!
50 | 已打开 (%s)
51 | 已关闭 (%s)
52 | 主机未响应!
53 |
54 | 响应时间:
55 | MAC 地址:
56 | 网卡厂商:
57 | 打开的端口:
58 | 关闭的端口:
59 | 未知
60 |
61 | 文件已保存!
62 | 选择目标文件
63 | 保存
64 | 文件已存在
65 | 是否需要覆盖文件?
66 |
67 | 主机发掘
68 | 正在使用的方法,并不需要有root权限。在将来的版本将会有更先进的技术,非root权限下的功能将更加完美。\n\n这儿说明软件是怎样工作的: \n1. 计算子网络范围\n2. 重复连接 IP 并验证之\n3. 首选它将发送一个ICMP包Ping主机,或者回显在TCP/7 (使用 InetAddress.isReachable())\n4. 如果不起作用,则尝试利用一些常用端口进行连接,如: 135, 139, 22, 111, 80\n5. 如果以上方式都没有成功,则是未发掘到主机
69 | 端口扫描
70 | 端口扫描是事件驱动,使用JAVA选择器和Socket通道。\n在以毫秒为单位的时间注册Socket创建时会产生一个假超时,会定期检查它。\n端口扫描方式,如发掘,使用完全的TCP连接扫描。(将来结合root功能将有更多的粒度连接。)\n\n同一时间最多能有127个Sockets通信进程,所以这并不总是精确的,但是很快。同样的,将来会有一个新功能以适应请求发出以及主机响应之间的时间时间(网络拥挤控制类软件)\n\n当TCP连接是成功的,则认为端口是开放的;而当监听结束时仍未发现任何服务或者过滤器超时则认为端口是关闭的。
71 | 链接
72 | - 扫描 TCP 连接:http://nmap.org/book/man-port-scanning-techniques.html#id421401\n\n- 主机发掘:http://nmap.org/book/man-host-discovery.html\n\n- 安智网汉化(http://goapk.com)
73 |
74 | 帮助
75 | 导出
76 | 學分
77 | 发掘设置
78 | 端口扫描设置
79 | 高级设置
80 |
81 | 解析主机名
82 | 使用系統 DNS來解析IP地址
83 | 震动
84 | 当扫描完成后震动
85 | 速率控制
86 | 启用速率自动检测
87 | 自定义速率
88 | 主机发掘的毫秒数
89 | 起始端口
90 | 扫描时的起始 TCP 端口。 1-65535
91 | 终止端口
92 | 扫描时的终止 TCP 端口。1-65535
93 | 服务广告
94 | 连接到TCP端口并打印出利用监听服务获取的信息(将产生一定的流量)
95 | 自定义超时
96 | 手动设置连接超时
97 | 连接超时
98 | 端口连接超时的毫秒数
99 | Allow mobile discovery
100 | Scan over edge/3g/... usually leading to strange results, if any
101 | SSH 用户
102 | SSH 连接的用户名
103 | 发掘线程
104 | 发掘主机的最大线程数(1-256)
105 | 更新信用卡資料庫
106 | 获取并更新MAC地址数据库
107 | 是否需要下载网卡数据库? (~%sk)
108 | 已升级数据库!更新 %s 个新条目 ...
109 | Version
110 | Website
111 | Contact
112 | Network interface
113 | Choose which interface to use
114 | Discover Method
115 | Change to different method of host discovery
116 | Choose a method
117 | First IP address to scan
118 | IP end
119 | Last IP address to scan
120 | Custom IP range
121 | Manually set start/end IPs
122 |
123 | 错误:起始端口大于终止端口!
124 | 错误:线程数必须介于1和256!
125 | 错误:文件传输中断!
126 | Error: Value is not a valid IP address !
127 |
128 |
129 | - Ping/connect (default)
130 | - DNS requests
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/res/values-zh-rTW/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 | Network Discovery
8 | 載入中
9 | 是
10 | 否
11 | 發掘
12 | 取消
13 | 匯出
14 | 關閉
15 | 掃瞄
16 | 選項
17 | 返回
18 | 信息
19 | 港口
20 |
21 | 必須從市場上安裝 %s !
22 |
23 | Wifi 已開啟
24 | Wifi 啟用中
25 | Wifi 關閉中
26 | Wifi 已關閉
27 | Wifi 掃瞄中
28 | Wifi是用 %s 聯入的
29 | 正在從 %s 獲取IP位址
30 | Wifi 狀態未知
31 |
32 | 開始發掘 ...
33 | 發掘完成!
34 | 已取消發掘!
35 | 代理錯誤
36 | 發掘已被取消,由於一個MAC位址出現了多次,您可能是在一個代理環境下。\n\n從瀏覽器轉到您的網關:http://%s
37 | 安裝: Root
38 | 是否需要以ROOT權限安裝後台掃瞄程式?
39 | 程式重啟中 ...
40 | Press Discover to start
41 |
42 | 掃瞄 IP
43 | 輸入一個IP位址或者域名以供掃瞄,例如 scanme.nmap.org
44 | 未發現開啟的通訊埠!
45 | 無相關操作!
46 | 連接
47 | 開始掃瞄 ...
48 | 掃瞄完成!
49 | 已取消掃瞄!
50 | 已開啟 (%s)
51 | 已關閉 (%s)
52 | 主機未響應!
53 |
54 | 響應時間:
55 | MAC 位址:
56 | 網卡廠商:
57 | 開啟的通訊埠:
58 | 關閉的通訊埠:
59 | 未知
60 |
61 | 檔案已儲存!
62 | 選取目標檔案
63 | 儲存
64 | 檔案已存在
65 | 是否需要覆寫檔案?
66 |
67 | 主機發掘
68 | 正在使用的方法,並不需要有root權限。在將來的版本將會有更先進的技術,非root權限下的功能將更加完美。\n\n這兒說明軟體是怎樣工作的: \n1. 計算子網路範圍\n2. 重複連接 IP 並驗證之\n3. 首選它將傳送一個ICMP包Ping主機,或者回顯在TCP/7 (使用 InetAddress.isReachable())\n4. 如果不起作用,則嘗試利用一些常用通訊埠進行連接,如: 135, 139, 22, 111, 80\n5. 如果以上方式都沒有成功,則是未發掘到主機
69 | 通訊埠掃瞄
70 | 通訊埠掃瞄是事件驅動,使用JAVA選取器和Socket通道。\n在以毫秒為單位的時間註冊Socket建立時會產生一個假逾時,會定期檢查它。\n通訊埠掃瞄方式,如發掘,使用完全的TCP連接掃瞄。(將來結合root功能將有更多的粒度連接。)\n\n同一時間最多能有127個Sockets通信進程,所以這並不總是精確的,但是很快。同樣的,將來會有一個新功能以適應要求發出以及主機響應之間的時間時間(網路擁擠控制類別軟體)\n\n當TCP連接是成功的,則認為通訊埠是開放的;而當監聽結束時仍未發現任何服務或者過濾器逾時則認為通訊埠是關閉的。
71 | 連結
72 | - 掃瞄 TCP 連接:http://nmap.org/book/man-port-scanning-techniques.html#id421401\n\n- 主機發掘:http://nmap.org/book/man-host-discovery.html\n\n- 安智網中文化 (http://goapk.com)
73 |
74 | 說明
75 | 匯出
76 | 学分
77 | 發掘設定
78 | 通訊埠掃瞄設定
79 | 進階設定
80 |
81 | 剖析主機名
82 | 使用系统DNS来解析IP地址
83 | 震動
84 | 當掃瞄完成後震動
85 | 速率控制
86 | 啟用速率自動偵測
87 | 自訂速率
88 | 主機發掘的毫秒數
89 | 開始通訊埠
90 | 掃瞄時的開始 TCP 通訊埠。 1-65535
91 | 終止通訊埠
92 | 掃瞄時的終止 TCP 通訊埠。1-65535
93 | 服務廣告
94 | 連接到TCP通訊埠並列印出利用監聽服務獲取的訊息(將產生一定的資料流量)
95 | 自訂逾時
96 | 手動設定連接逾時
97 | 連接逾時
98 | 通訊埠連接逾時的毫秒數
99 | Allow mobile discovery
100 | Scan over edge/3g/... usually leading to strange results, if any
101 | SSH 使用者
102 | SSH 連接的使用者名
103 | 發掘執行緒
104 | 發掘主機的最大執行緒數(1-256)
105 | 更新信用卡资料库
106 | 獲取並更新MAC位址資料庫
107 | 是否需要下載網卡資料庫? (~%sk)
108 | 已升級資料庫!更新 %s 個新項目 ...
109 | Version
110 | Website
111 | Contact
112 | Network interface
113 | Choose which interface to use
114 | Discover Method
115 | Change to different method of host discovery
116 | Choose a method
117 | First IP address to scan
118 | IP end
119 | Last IP address to scan
120 | Custom IP range
121 | Manually set start/end IPs
122 |
123 | 錯誤:開始通訊埠大於終止通訊埠!
124 | 錯誤:執行緒數必須介於1和256!
125 | 錯誤:檔案傳輸中斷!
126 | Error: Value is not a valid IP address !
127 |
128 |
129 | - Ping/connect (default)
130 | - DNS requests
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 | - 0
10 | - 1
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 | #cccccc
8 | #ff9900
9 | #ff6600
10 | #ff3300
11 |
12 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 | Network Discovery
8 | Loading
9 | Yes
10 | No
11 | Ok
12 | Discover
13 | Cancel
14 | Export
15 | Close
16 | Scan
17 | Options
18 | Back
19 | Info
20 | Ports
21 | Remove
22 |
23 | Downloading and installing %s database ...
24 | Creating Services database ...\nThis may take a while ...
25 |
26 | %s must be installed from the market !
27 |
28 | Wifi is enabled
29 | Wifi is enabling
30 | Wifi is disabling
31 | Wifi is disabled
32 | Wifi is scanning
33 | Wifi is associating with %s
34 | Obtaining IP address from %s
35 | Wifi state unknown
36 |
37 | IP: %1$s/%2$d (%3$s)
38 | CARRIER: %s
39 | SSID: %s
40 | MODE: %s
41 | WiFi (%1$s %2$s)
42 | Mobile
43 | Ethernet (Not supported yet)
44 | Unknown
45 |
46 | Discovery started ...
47 | Discovery finished !
48 | Discovery canceled !
49 | Proxy Error
50 | Discovery is canceled, because a mac address appeared multiple times, you probably are behind a proxy.\n\nGo to your Gateway from the browser : http://%s
51 | Installation: Root
52 | Do you want to install the scan daemon for root ?
53 | Restarting application ...
54 | Press Discover to start
55 | Choose an action
56 | Scan ports
57 | Change name
58 | Name saved!
59 | Name deleted!
60 | MyPhone
61 |
62 | Scan IP
63 | Enter an IP address or FQDN to scan, i.e. scanme.nmap.org
64 | No open port found !
65 | No associated action !
66 | Connect
67 | Scan started ...
68 | Scan finished !
69 | Scan canceled !
70 | Open (%s)
71 | Closed (%s)
72 | Host unreachable !
73 | Port %s/tcp
74 |
75 | Response time:
76 | MAC Address:
77 | NIC vendor:
78 | Open ports:
79 | Closed ports:
80 | Unknown
81 |
82 | File saved !
83 | Choose file destination
84 | Save
85 | File already exists
86 | Do you want to overwrite ?
87 |
88 | Hosts discovery
89 | The method that is being used, does not need to have root privileges. In future release there will be more advanced techniques, once the non-root ones are polished.\n\nHere is how it works: \n1. Calculate the subnetwork range\n2. Iterate throught IP and query them\n3. First it sends an ICMP ping or Echo on tcp/7 (with InetAddress.isReachable())\n4. If it does not work, it tries to connect() on well known open tcp ports such as: 135, 139, 22, 111, 80\n5. If none of the above is successful, the host is not discovered
90 | Port scan
91 | Port scan is event driven, using Java\'s Selector and SocketChannel.\nThere is a fake timeout by registrering the time in ms at socket\'s creation and checking regularly this value.\nThe port scan method, as discovery, uses full tcp connection check. (will be more granular in the future with root features.)\n\nA maximum of 127 Sockets are opened at a time, so this is not always accurate, but quite fast. Again, a new feature is coming that will adapt times between requests according to host response time (kind of software network congestion control)\n\nA port is considered open when tcp connect() is fully successful, closed when no service is listening on the other end, or filtered when the timeout is reached.
92 | Links
93 | - TCP connect scan: http://nmap.org/book/man-port-scanning-techniques.html#id421401\n\n- Host discovery: http://nmap.org/book/man-host-discovery.html
94 |
95 | Help
96 | Export
97 | Credits
98 | Discovery
99 | Port Scan
100 | General
101 |
102 | Resolve Hostname
103 | Use system DNS to resolve ip addresses
104 | Vibrate
105 | Vibrate when Scan is completed
106 | Rate control
107 | Enable automatic rate detection
108 | Custom rate
109 | Rate of discovery in millisecondes
110 | First Port
111 | First TCP Port to scan. 1-65535
112 | Last Port
113 | Last TCP Port to scan. 1-65535
114 | Services banners
115 | Read banner from a connected socket (ex.: SSH-2.0-OpenSSH_5.1p1)
116 | Custom timeout
117 | Manually set connect timeout
118 | Connect timeout
119 | Timeout of a port connection in millisecondes
120 | Allow mobile discovery
121 | Scan over edge/3g/... usually leading to strange results, if any
122 | SSH User
123 | Username for the SSH connection
124 | Threads pool
125 | Maximum number of threads to use in host discovery (1-256)
126 | Update NIC Database
127 | Pull and update MAC addresses database
128 | Do you want to download %1$s ? (~%2$sk)
129 | Database updated ! %s new entries ...
130 | Version
131 | Website
132 | Contact
133 | Network interface
134 | Choose which interface to use
135 | Discover Method
136 | Change to different method of host discovery
137 | Choose a method
138 | IP start
139 | First IP address to scan
140 | IP end
141 | Last IP address to scan
142 | Custom IP range
143 | Manually set start/end IPs
144 | Custom CIDR
145 | Manually set CIDR (defines subnet)
146 | Change CIDR
147 |
148 | Error: First is bigger than Last !
149 | Error: Number of Threads must be between 1 and 256 !
150 | Error: File transfer interrupted !
151 | Error: Value is not a valid IP address !
152 |
153 |
154 | - Ping/connect (default)
155 | - DNS requests
156 |
157 |
158 |
159 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
23 |
26 |
31 |
37 |
41 |
44 |
48 |
52 |
53 |
--------------------------------------------------------------------------------
/res/xml/preferences.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
9 |
10 |
13 |
19 |
24 |
29 |
34 |
35 |
36 |
39 |
47 |
52 |
58 |
64 |
69 |
75 |
80 |
86 |
91 |
97 |
98 |
99 |
102 |
107 |
113 |
119 |
124 |
129 |
136 |
137 |
138 |
141 |
142 |
143 |
144 |
146 |
149 |
152 |
155 |
156 |
157 |
158 |
--------------------------------------------------------------------------------
/scripts/create-nic-db.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | '''
4 | Copyright (C) 2009-2013 Aubort Jean-Baptiste (Rorist)
5 | Licensed under GNU's GPL 2, see README
6 | '''
7 |
8 | import sqlite3, os, urllib, re
9 |
10 | db = 'oui.db'
11 | url = 'http://standards.ieee.org/regauth/oui/oui.txt'
12 |
13 | #Download the file
14 | webFile = urllib.urlopen(url)
15 | localFile = open(url.split('/')[-1], 'w')
16 | localFile.write(webFile.read())
17 | webFile.close()
18 | localFile.close()
19 |
20 | #Create the DB
21 | try:
22 | os.remove(db)
23 | except OSError, err:
24 | print err
25 | conn = sqlite3.connect(db)
26 | c = conn.cursor()
27 | c.execute("create table oui (mac text, vendor text)")
28 |
29 | for line in open("oui.txt"):
30 | r = re.search('^\s*([0-9A-Fa-f]*)\s*\(base 16\)\s*(.*)$', line)
31 | if r:
32 | mac = r.group(1)
33 | vendor = r.group(2).replace("'", "`").strip()
34 | try:
35 | c.execute("insert into oui values ('%s', '%s')"%(mac, vendor))
36 | except sqlite3.OperationalError, err:
37 | print err
38 |
39 | #print "%s records"%i
40 |
41 | conn.commit()
42 | c.close()
43 |
--------------------------------------------------------------------------------
/scripts/create-probes-db.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | '''
4 | Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
5 | Licensed under GNU's GPL 2, see README
6 | '''
7 |
8 | import sqlite3, os, urllib, re
9 |
10 | db = '../res/raw/probes.db'
11 | url = 'http://nmap.org/svn/nmap-service-probes'
12 |
13 | #Download the file
14 | webFile = urllib.urlopen(url)
15 | localFile = open(url.split('/')[-1], 'w')
16 | localFile.write(webFile.read())
17 | webFile.close()
18 | localFile.close()
19 |
20 | #Create the DB
21 | try:
22 | os.remove(db)
23 | except OSError, err:
24 | print err
25 | conn = sqlite3.connect(db)
26 | c = conn.cursor()
27 | c.execute("CREATE TABLE probes (_id INTEGER PRIMARY KEY, service TEXT, regex TEXT, desc TEXT);")
28 | c.execute("CREATE INDEX regexIndex ON probes (regex);")
29 |
30 | ptn1 = re.compile("^(soft)?match (ftp|sftp|ssh|telnet|http) m\|(.*?)\|[si]? ?[pvihod]?/?(.*?)")
31 | ptn2 = re.compile("^(soft)?match (ftp|sftp|ssh|telnet|http) m\/(.*?)\/[si]? ?[pvihod]?/?(.*?)")
32 |
33 | for line in open("nmap-service-probes"):
34 | if "Probes" in line:
35 | print line
36 | elif "match " in line:
37 | line = line.replace("'", "''").replace("\\0", "\\\\0")
38 | # First pass
39 | fnd = re.match(ptn1, line)
40 | if fnd:
41 | if fnd.group(3) != None:
42 | try:
43 | c.execute("INSERT INTO probes ('service', 'regex', 'desc') VALUES ('%s', '%s', '%s');" % (fnd.group(2), fnd.group(3), fnd.group(4)))
44 | except sqlite3.OperationalError, err:
45 | print err
46 | # Second pass
47 | fnd = re.match(ptn2, line)
48 | if fnd:
49 | if fnd.group(3) != None:
50 | try:
51 | c.execute("INSERT INTO probes ('service', 'regex', 'desc') VALUES ('%s', '%s', '%s');\n" % (fnd.group(2), fnd.group(3), fnd.group(4)))
52 | except sqlite3.OperationalError, err:
53 | print err
54 |
55 | conn.commit()
56 | c.close()
57 | os.remove("nmap-service-probes")
58 |
59 |
--------------------------------------------------------------------------------
/scripts/create-services-db.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | '''
4 | Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
5 | Licensed under GNU's GPL 2, see README
6 | '''
7 |
8 | import sqlite3, os, urllib, re
9 |
10 | db = '../res/raw/services.db'
11 | url = 'http://nmap.org/svn/nmap-services'
12 |
13 | #Download the file
14 | webFile = urllib.urlopen(url)
15 | localFile = open(url.split('/')[-1], 'w')
16 | localFile.write(webFile.read())
17 | webFile.close()
18 | localFile.close()
19 |
20 | #Create the DB
21 | try:
22 | os.remove(db)
23 | except OSError, err:
24 | print err
25 | conn = sqlite3.connect(db)
26 |
27 | c = conn.cursor()
28 | c.execute("CREATE TABLE services (_id INTEGER PRIMARY KEY, service TEXT, port INTEGER);")
29 | c.execute("CREATE INDEX portIndex ON services (port);")
30 |
31 | ptn = re.compile("([a-zA-Z0-9\-]+)[\s\t]+([0-9]+)\/tcp")
32 | for line in open("nmap-services"):
33 | if "/tcp" in line and "unknown" not in line:
34 | fnd = re.match(ptn, line)
35 | if fnd:
36 | try:
37 | c.execute("INSERT INTO services ('port', 'service') VALUES (%s, '%s');" % (fnd.group(2), fnd.group(1)))
38 | except sqlite3.OperationalError, err:
39 | print err
40 |
41 | conn.commit()
42 | c.close()
43 | os.remove("nmap-services")
44 |
45 |
--------------------------------------------------------------------------------
/scripts/make-native.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
4 | # Licensed under GNU's GPL 2, see README
5 | #
6 |
7 | BASE=$(dirname `cd ${0%/*} && echo $PWD}`)
8 | PATH_TO_NATIVE="$BASE/native"
9 | PATH_TO_SRC='/opt/android-src'
10 | SCAND_PATH='external/scand'
11 | #LIBCOMMAND_PATH='external/libcommand'
12 |
13 | cd $PATH_TO_SRC
14 | mkdir -p development/tools/layoutopt/app/src/resources
15 | rm -rf out/target/product/generic/system/bin
16 | rm -rf out/target/product/generic/system/lib
17 |
18 | # SCAND
19 | rm -rf $SCAND_PATH; mkdir $SCAND_PATH
20 | cp $PATH_TO_NATIVE/scand/* $SCAND_PATH/.
21 |
22 | # LIBCOMMAND.SO
23 | #rm -rf $LIBCOMMAND_PATH; mkdir $LIBCOMMAND_PATH
24 | #cp $PATH_TO_NATIVE/libcommand/* $LIBCOMMAND_PATH/.
25 | #if [ "`cat $PATH_TO_SRC/build/core/prelink-linux-arm.map | grep 0x9A000000 | wc -l`" -eq 0 ]; then
26 | # echo 'libcommand.so 0x9A000000' >> $PATH_TO_SRC/build/core/prelink-linux-arm.map
27 | #fi
28 |
29 | # Build
30 | make scand && {
31 | echo "\nBuild Successfull!"
32 | mkdir -p $BASE/libs/armeabi
33 | cp out/target/product/generic/system/bin/scand $BASE/res/raw/scand
34 | #cp out/target/product/generic/system/lib/libcommand.so $BASE/libs/armeabi/libcommand.so
35 | }
36 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/AbstractDiscovery.java:
--------------------------------------------------------------------------------
1 | package info.lamatricexiste.network;
2 |
3 | import info.lamatricexiste.network.Network.HostBean;
4 | import info.lamatricexiste.network.Utils.Prefs;
5 |
6 | import java.lang.ref.WeakReference;
7 |
8 | import android.content.Context;
9 | import android.os.AsyncTask;
10 | import android.os.Vibrator;
11 |
12 | public abstract class AbstractDiscovery extends AsyncTask {
13 |
14 | //private final String TAG = "AbstractDiscovery";
15 |
16 | protected int hosts_done = 0;
17 | final protected WeakReference mDiscover;
18 |
19 | protected long ip;
20 | protected long start = 0;
21 | protected long end = 0;
22 | protected long size = 0;
23 |
24 | public AbstractDiscovery(ActivityDiscovery discover) {
25 | mDiscover = new WeakReference(discover);
26 | }
27 |
28 | public void setNetwork(long ip, long start, long end) {
29 | this.ip = ip;
30 | this.start = start;
31 | this.end = end;
32 | }
33 |
34 | abstract protected Void doInBackground(Void... params);
35 |
36 | @Override
37 | protected void onPreExecute() {
38 | size = (int) (end - start + 1);
39 | if (mDiscover != null) {
40 | final ActivityDiscovery discover = mDiscover.get();
41 | if (discover != null) {
42 | discover.setProgress(0);
43 | }
44 | }
45 | }
46 |
47 | @Override
48 | protected void onProgressUpdate(HostBean... host) {
49 | if (mDiscover != null) {
50 | final ActivityDiscovery discover = mDiscover.get();
51 | if (discover != null) {
52 | if (!isCancelled()) {
53 | if (host[0] != null) {
54 | discover.addHost(host[0]);
55 | }
56 | if (size > 0) {
57 | discover.setProgress((int) (hosts_done * 10000 / size));
58 | }
59 | }
60 |
61 | }
62 | }
63 | }
64 |
65 | @Override
66 | protected void onPostExecute(Void unused) {
67 | if (mDiscover != null) {
68 | final ActivityDiscovery discover = mDiscover.get();
69 | if (discover != null) {
70 | if (discover.prefs.getBoolean(Prefs.KEY_VIBRATE_FINISH,
71 | Prefs.DEFAULT_VIBRATE_FINISH) == true) {
72 | Vibrator v = (Vibrator) discover.getSystemService(Context.VIBRATOR_SERVICE);
73 | v.vibrate(ActivityDiscovery.VIBRATE);
74 | }
75 | discover.makeToast(R.string.discover_finished);
76 | discover.stopDiscovering();
77 | }
78 | }
79 | }
80 |
81 | @Override
82 | protected void onCancelled() {
83 | if (mDiscover != null) {
84 | final ActivityDiscovery discover = mDiscover.get();
85 | if (discover != null) {
86 | discover.makeToast(R.string.discover_canceled);
87 | discover.stopDiscovering();
88 | }
89 | }
90 | super.onCancelled();
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/ActivityMain.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network;
7 |
8 | import info.lamatricexiste.network.Network.NetInfo;
9 | import info.lamatricexiste.network.Utils.Db;
10 | import info.lamatricexiste.network.Utils.DbUpdate;
11 | import info.lamatricexiste.network.Utils.Prefs;
12 |
13 | import java.io.IOException;
14 | import java.lang.ref.WeakReference;
15 |
16 | import android.app.Activity;
17 | import android.app.ProgressDialog;
18 | import android.content.ContentValues;
19 | import android.content.Context;
20 | import android.content.Intent;
21 | import android.content.SharedPreferences;
22 | import android.content.SharedPreferences.Editor;
23 | import android.content.pm.PackageManager.NameNotFoundException;
24 | import android.database.sqlite.SQLiteDatabase;
25 | import android.os.AsyncTask;
26 | import android.os.Bundle;
27 | import android.preference.PreferenceManager;
28 | import android.util.Log;
29 | import android.view.Window;
30 |
31 | final public class ActivityMain extends Activity {
32 |
33 | public final static String TAG = "ActivityMain";
34 | public static final String PKG = "info.lamatricexiste.network";
35 | public static SharedPreferences prefs = null;
36 |
37 | @Override
38 | public void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
41 | setContentView(R.layout.main);
42 | setTitle(R.string.app_loading);
43 | final Context ctxt = this;
44 | prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
45 |
46 | // Reset interface
47 | Editor edit = prefs.edit();
48 | edit.putString(Prefs.KEY_INTF, Prefs.DEFAULT_INTF);
49 |
50 | phase2(ctxt);
51 | }
52 |
53 | private void phase2(final Context ctxt) {
54 |
55 | class DbUpdateProbes extends DbUpdate {
56 | public DbUpdateProbes() {
57 | super(ActivityMain.this, Db.DB_PROBES, "probes", "regex", 298);
58 | }
59 |
60 | protected void onPostExecute(Void unused) {
61 | super.onPostExecute(unused);
62 | final Activity d = mActivity.get();
63 | phase3(d);
64 | }
65 |
66 | protected void onCancelled() {
67 | super.onCancelled();
68 | final Activity d = mActivity.get();
69 | phase3(d);
70 | }
71 | }
72 |
73 | class DbUpdateNic extends DbUpdate {
74 | public DbUpdateNic() {
75 | super(ActivityMain.this, Db.DB_NIC, "oui", "mac", 253);
76 | }
77 |
78 | protected void onPostExecute(Void unused) {
79 | super.onPostExecute(unused);
80 | final Activity d = mActivity.get();
81 | new DbUpdateProbes();
82 | }
83 |
84 | protected void onCancelled() {
85 | super.onCancelled();
86 | final Activity d = mActivity.get();
87 | new DbUpdateProbes();
88 | }
89 | }
90 |
91 | // CheckNicDb
92 | try {
93 | if (prefs.getInt(Prefs.KEY_RESET_NICDB, Prefs.DEFAULT_RESET_NICDB) != getPackageManager()
94 | .getPackageInfo(PKG, 0).versionCode) {
95 | new DbUpdateNic();
96 | } else {
97 | // There is a NIC Db installed
98 | phase3(ctxt);
99 | }
100 | } catch (NameNotFoundException e) {
101 | phase3(ctxt);
102 | } catch (ClassCastException e) {
103 | Editor edit = prefs.edit();
104 | edit.putInt(Prefs.KEY_RESET_NICDB, 1);
105 | edit.commit();
106 | phase3(ctxt);
107 | }
108 | }
109 |
110 | private void phase3(final Context ctxt) {
111 | // Install Services DB
112 |
113 | try {
114 | if (prefs.getInt(Prefs.KEY_RESET_SERVICESDB, Prefs.DEFAULT_RESET_SERVICESDB) != getPackageManager()
115 | .getPackageInfo(PKG, 0).versionCode) {
116 | new CreateServicesDb(ActivityMain.this).execute();
117 | } else {
118 | startDiscoverActivity(ctxt);
119 | }
120 | } catch (NameNotFoundException e) {
121 | startDiscoverActivity(ctxt);
122 | }
123 | }
124 |
125 | private void startDiscoverActivity(final Context ctxt) {
126 | startActivity(new Intent(ctxt, ActivityDiscovery.class));
127 | finish();
128 | }
129 |
130 | static class CreateServicesDb extends AsyncTask {
131 | private WeakReference mActivity;
132 | private ProgressDialog progress;
133 |
134 | public CreateServicesDb(Activity activity) {
135 | mActivity = new WeakReference(activity);
136 | }
137 |
138 | @Override
139 | protected void onPreExecute() {
140 | final Activity d = mActivity.get();
141 | if (d != null) {
142 | try {
143 | d.setProgressBarIndeterminateVisibility(true);
144 | progress = ProgressDialog.show(d, "", d.getString(R.string.task_services));
145 | } catch (Exception e) {
146 | if (e != null) {
147 | Log.e(TAG, e.getMessage());
148 | }
149 | }
150 | }
151 | }
152 |
153 | @Override
154 | protected Void doInBackground(Void... params) {
155 | final Activity d = mActivity.get();
156 | if (d != null) {
157 | Db db = new Db(d.getApplicationContext());
158 | try {
159 | // db.copyDbToDevice(R.raw.probes, Db.DB_PROBES);
160 | db.copyDbToDevice(R.raw.services, Db.DB_SERVICES);
161 | db.copyDbToDevice(R.raw.saves, Db.DB_SAVES);
162 | // Save this device in db
163 | NetInfo net = new NetInfo(d.getApplicationContext());
164 | ContentValues values = new ContentValues();
165 | values.put("_id", 0);
166 | if (net.macAddress == null) {
167 | net.macAddress = NetInfo.NOMAC;
168 | }
169 | values.put("mac", net.macAddress.replace(":", "").toUpperCase());
170 | values.put("name", d.getString(R.string.discover_myphone_name));
171 | SQLiteDatabase data = Db.openDb(Db.DB_SAVES);
172 | data.insert("nic", null, values);
173 | data.close();
174 | } catch (NullPointerException e) {
175 | Log.e(TAG, e.getMessage());
176 | } catch (IOException e) {
177 | if (e != null) {
178 | if (e.getMessage() != null) {
179 | Log.e(TAG, e.getMessage());
180 | } else {
181 | Log.e(TAG, "Unknown IOException");
182 | }
183 | e.printStackTrace();
184 | }
185 | }
186 | }
187 | return null;
188 | }
189 |
190 | @Override
191 | protected void onPostExecute(Void unused) {
192 | final ActivityMain d = (ActivityMain) mActivity.get();
193 | if (d != null) {
194 | d.setProgressBarIndeterminateVisibility(true);
195 | if (progress.isShowing()) {
196 | progress.dismiss();
197 | }
198 | try {
199 | Editor edit = prefs.edit();
200 | edit.putInt(Prefs.KEY_RESET_SERVICESDB, d.getPackageManager().getPackageInfo(
201 | PKG, 0).versionCode);
202 | edit.commit();
203 | } catch (NameNotFoundException e) {
204 | Log.e(TAG, e.getMessage());
205 | } finally {
206 | d.startDiscoverActivity(d);
207 | }
208 | }
209 | }
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/ActivityNet.java:
--------------------------------------------------------------------------------
1 | package info.lamatricexiste.network;
2 |
3 | import info.lamatricexiste.network.Network.NetInfo;
4 | import info.lamatricexiste.network.Utils.Prefs;
5 |
6 | import android.app.Activity;
7 | import android.content.BroadcastReceiver;
8 | import android.content.Context;
9 | import android.content.Intent;
10 | import android.content.IntentFilter;
11 | import android.net.ConnectivityManager;
12 | import android.net.NetworkInfo;
13 | import android.net.wifi.SupplicantState;
14 | import android.net.wifi.WifiInfo;
15 | import android.net.wifi.WifiManager;
16 | import android.os.Bundle;
17 | import android.preference.PreferenceManager;
18 | import android.content.SharedPreferences;
19 | import android.util.Log;
20 |
21 | public abstract class ActivityNet extends Activity {
22 |
23 | private final String TAG = "NetState";
24 | private ConnectivityManager connMgr;
25 |
26 | protected final static String EXTRA_WIFI = "wifiDisabled";
27 | protected Context ctxt;
28 | protected SharedPreferences prefs = null;
29 | protected NetInfo net = null;
30 | protected String info_ip_str = "";
31 | protected String info_in_str = "";
32 | protected String info_mo_str = "";
33 |
34 | @Override
35 | public void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | ctxt = getApplicationContext();
38 | prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
39 | connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
40 | net = new NetInfo(ctxt);
41 | }
42 |
43 | @Override
44 | public void onResume() {
45 | super.onResume();
46 | setButtons(true);
47 | // Listening for network events
48 | IntentFilter filter = new IntentFilter();
49 | filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
50 | filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
51 | filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
52 | registerReceiver(receiver, filter);
53 | }
54 |
55 | @Override
56 | public void onPause() {
57 | super.onPause();
58 | unregisterReceiver(receiver);
59 | }
60 |
61 | protected abstract void setInfo();
62 |
63 | protected abstract void setButtons(boolean disable);
64 |
65 | protected abstract void cancelTasks();
66 |
67 | private BroadcastReceiver receiver = new BroadcastReceiver() {
68 | public void onReceive(Context ctxt, Intent intent) {
69 | info_ip_str = "";
70 | info_mo_str = "";
71 |
72 | // Wifi state
73 | String action = intent.getAction();
74 | if (action != null) {
75 | if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
76 | int WifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, -1);
77 | //Log.d(TAG, "WifiState=" + WifiState);
78 | switch (WifiState) {
79 | case WifiManager.WIFI_STATE_ENABLING:
80 | info_in_str = getString(R.string.wifi_enabling);
81 | break;
82 | case WifiManager.WIFI_STATE_ENABLED:
83 | info_in_str = getString(R.string.wifi_enabled);
84 | break;
85 | case WifiManager.WIFI_STATE_DISABLING:
86 | info_in_str = getString(R.string.wifi_disabling);
87 | break;
88 | case WifiManager.WIFI_STATE_DISABLED:
89 | info_in_str = getString(R.string.wifi_disabled);
90 | break;
91 | default:
92 | info_in_str = getString(R.string.wifi_unknown);
93 | }
94 | }
95 |
96 | if (action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION) && net.getWifiInfo()) {
97 | SupplicantState sstate = net.getSupplicantState();
98 | //Log.d(TAG, "SupplicantState=" + sstate);
99 | if (sstate == SupplicantState.SCANNING) {
100 | info_in_str = getString(R.string.wifi_scanning);
101 | } else if (sstate == SupplicantState.ASSOCIATING) {
102 | info_in_str = getString(R.string.wifi_associating,
103 | (net.ssid != null ? net.ssid : (net.bssid != null ? net.bssid
104 | : net.macAddress)));
105 | } else if (sstate == SupplicantState.COMPLETED) {
106 | info_in_str = getString(R.string.wifi_dhcp, net.ssid);
107 | }
108 | }
109 | }
110 |
111 | // 3G(connected) -> Wifi(connected)
112 | // Support Ethernet, with ConnectivityManager.TYPE_ETHER=3
113 | final NetworkInfo ni = connMgr.getActiveNetworkInfo();
114 | if (ni != null) {
115 | //Log.i(TAG, "NetworkState="+ni.getDetailedState());
116 | if (ni.getDetailedState() == NetworkInfo.DetailedState.CONNECTED) {
117 | int type = ni.getType();
118 | //Log.i(TAG, "NetworkType="+type);
119 | if (type == ConnectivityManager.TYPE_WIFI) { // WIFI
120 | net.getWifiInfo();
121 | if (net.ssid != null) {
122 | net.getIp();
123 | info_ip_str = getString(R.string.net_ip, net.ip, net.cidr, net.intf);
124 | info_in_str = getString(R.string.net_ssid, net.ssid);
125 | info_mo_str = getString(R.string.net_mode, getString(
126 | R.string.net_mode_wifi, net.speed, WifiInfo.LINK_SPEED_UNITS));
127 | setButtons(false);
128 | }
129 | } else if (type == ConnectivityManager.TYPE_MOBILE) { // 3G
130 | if (prefs.getBoolean(Prefs.KEY_MOBILE, Prefs.DEFAULT_MOBILE)
131 | || prefs.getString(Prefs.KEY_INTF, Prefs.DEFAULT_INTF) != null) {
132 | net.getMobileInfo();
133 | if (net.carrier != null) {
134 | net.getIp();
135 | info_ip_str = getString(R.string.net_ip, net.ip, net.cidr, net.intf);
136 | info_in_str = getString(R.string.net_carrier, net.carrier);
137 | info_mo_str = getString(R.string.net_mode,
138 | getString(R.string.net_mode_mobile));
139 | setButtons(false);
140 | }
141 | }
142 | } else if (type == 3 || type == 9) { // ETH
143 | net.getIp();
144 | info_ip_str = getString(R.string.net_ip, net.ip, net.cidr, net.intf);
145 | info_in_str = "";
146 | info_mo_str = getString(R.string.net_mode) + getString(R.string.net_mode_eth);
147 | setButtons(false);
148 | Log.i(TAG, "Ethernet connectivity detected!");
149 | } else {
150 | Log.i(TAG, "Connectivity unknown!");
151 | info_mo_str = getString(R.string.net_mode)
152 | + getString(R.string.net_mode_unknown);
153 | }
154 | } else {
155 | cancelTasks();
156 | }
157 | } else {
158 | cancelTasks();
159 | }
160 |
161 | // Always update network info
162 | setInfo();
163 | }
164 | };
165 | }
166 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/AsyncPortscan.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | /**
7 | * Java NIO Documentation:
8 | * http://jfarcand.wordpress.com/2006/05/30/tricks-and-tips-with-nio-part-i-why-you-must-handle-op_write
9 | * http://jfarcand.wordpress.com/2006/07/06/tricks-and-tips-with-nio-part-ii-why-selectionkey-attach-is-evil/
10 | * http://jfarcand.wordpress.com/2006/07/07/tricks-and-tips-with-nio-part-iii-to-thread-or-not-to-thread/
11 | * http://jfarcand.wordpress.com/2006/07/19/httpweblogs-java-netblog20060719tricks-and-tips-nio-part-iv-meet-selectors/
12 | * http://jfarcand.wordpress.com/2006/09/21/tricks-and-tips-with-nio-part-v-ssl-and-nio-friend-or-foe
13 | * http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/
14 | */
15 |
16 | package info.lamatricexiste.network;
17 |
18 | import info.lamatricexiste.network.Utils.Prefs;
19 |
20 | import java.io.IOException;
21 | import java.lang.ref.WeakReference;
22 | import java.net.ConnectException;
23 | import java.net.InetAddress;
24 | import java.net.InetSocketAddress;
25 | import java.net.Socket;
26 | import java.net.UnknownHostException;
27 | import java.nio.ByteBuffer;
28 | import java.nio.channels.ClosedSelectorException;
29 | import java.nio.channels.SelectableChannel;
30 | import java.nio.channels.SelectionKey;
31 | import java.nio.channels.Selector;
32 | import java.nio.channels.SocketChannel;
33 | import java.nio.charset.Charset;
34 | import java.util.Iterator;
35 |
36 | import android.app.Activity;
37 | import android.content.SharedPreferences;
38 | import android.os.AsyncTask;
39 | import android.preference.PreferenceManager;
40 | import android.util.Log;
41 |
42 | public class AsyncPortscan extends AsyncTask {
43 |
44 | private final String TAG = "AsyncPortscan";
45 | private static final int TIMEOUT_SELECT = 300;
46 | private static long TIMEOUT_CONNECT = 1000 * 1000000; // ns
47 | private static final long TIMEOUT_RW = 3 * 1000 * 1000000; // ns
48 | private static final String E_REFUSED = "Connection refused";
49 | private static final String E_TIMEOUT = "The operation timed out";
50 | // TODO: Probe system to send other stuff than strings
51 | private static final String[] PROBES = new String[] { "", "\r\n\r\n", "GET / HTTP/1.0\r\n\r\n" };
52 | private static final int MAX_READ = 8 * 1024;
53 | private static final int WRITE_PASS = PROBES.length;
54 | private static final long WRITE_COOLDOWN = 200 * 1000000; // ns
55 |
56 | private int rate;
57 | private boolean select = true;
58 | private Selector selector;
59 |
60 | protected String ipAddr = null;
61 | protected int port_start = 0;
62 | protected int port_end = 0;
63 | protected int nb_port = 0;
64 | private boolean getBanner = false;
65 | private ByteBuffer byteBuffer = ByteBuffer.allocate(MAX_READ);
66 | private Charset charset = Charset.forName("UTF-8");
67 |
68 | public final static int OPEN = 0;
69 | public final static int CLOSED = 1;
70 | public final static int FILTERED = -1;
71 | public final static int UNREACHABLE = -2;
72 | public final static int TIMEOUT = -3;
73 |
74 | protected AsyncPortscan(Activity activity, String host, int _rate) {
75 | ipAddr = host;
76 | rate = _rate;
77 | TIMEOUT_CONNECT = rate * 1000000; // ms to ns
78 |
79 | // Preferences
80 | WeakReference mActivity = new WeakReference(activity);
81 | final Activity d = mActivity.get();
82 | if (d != null) {
83 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(d
84 | .getApplicationContext());
85 | getBanner = prefs.getBoolean(Prefs.KEY_BANNER, Prefs.DEFAULT_BANNER);
86 | }
87 | }
88 |
89 | @Override
90 | protected Void doInBackground(Void... params) {
91 | try {
92 | int step = 127;
93 | InetAddress ina = InetAddress.getByName(ipAddr);
94 | if (nb_port > step) {
95 | // FIXME: Selector leaks file descriptors (Dalvik bug)
96 | // http://code.google.com/p/android/issues/detail?id=4825
97 | for (int i = port_start; i <= port_end - step; i += step + 1) {
98 | if (select) {
99 | start(ina, i, i + ((i + step <= port_end - step) ? step : port_end - i));
100 | }
101 | }
102 | } else {
103 | start(ina, port_start, port_end);
104 | }
105 |
106 | } catch (UnknownHostException e) {
107 | Log.e(TAG, e.getMessage());
108 | publishProgress(0, UNREACHABLE, null);
109 | }
110 | return null;
111 | }
112 |
113 | private void start(final InetAddress ina, final int PORT_START, final int PORT_END) {
114 | select = true;
115 | try {
116 | selector = Selector.open();
117 | for (int j = PORT_START; j <= PORT_END; j++) {
118 | connectSocket(ina, j);
119 | }
120 | while (select && selector.keys().size() > 0) {
121 | if (selector.select(TIMEOUT_SELECT) > 0) {
122 | synchronized (selector.selectedKeys()) {
123 | Iterator iterator = selector.selectedKeys().iterator();
124 | while (iterator.hasNext()) {
125 | SelectionKey key = (SelectionKey) iterator.next();
126 | try {
127 | if (!key.isValid()) {
128 | continue;
129 | }
130 | // States
131 | final Data data = (Data) key.attachment();
132 |
133 | if (key.isConnectable()) {
134 | if (((SocketChannel) key.channel()).finishConnect()) {
135 | if (getBanner) {
136 | key.interestOps(SelectionKey.OP_READ
137 | | SelectionKey.OP_WRITE);
138 | data.state = OPEN;
139 | data.start = System.nanoTime();
140 | publishProgress(data.port, OPEN, null);
141 | } else {
142 | finishKey(key, OPEN);
143 | }
144 | }
145 |
146 | } else if (key.isReadable()) {
147 | try {
148 | byteBuffer.clear();
149 | final int numRead = ((SocketChannel) key.channel())
150 | .read(byteBuffer);
151 | if (numRead > 0) {
152 | String banner = new String(byteBuffer.array())
153 | .substring(0, numRead).trim();
154 | // Log.v(TAG, "read " + data.port +
155 | // " data=" + banner);
156 | finishKey(key, OPEN, banner);
157 | } else {
158 | key.interestOps(SelectionKey.OP_WRITE);
159 | }
160 | } catch (IOException e) {
161 | Log.e(TAG, e.getMessage());
162 | }
163 | } else if (key.isWritable()) {
164 | key.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
165 | if (System.nanoTime() - data.start > WRITE_COOLDOWN) {
166 | if (data.pass < WRITE_PASS) {
167 | // Log.v(TAG, "write " + data.port);
168 | // write something (blocking)
169 | final ByteBuffer bytedata = charset
170 | .encode(PROBES[data.pass]);
171 | final SocketChannel sock = (SocketChannel) key
172 | .channel();
173 | while (bytedata.hasRemaining()) {
174 | sock.write(bytedata);
175 | }
176 | bytedata.clear();
177 | data.start = System.nanoTime();
178 | data.pass++;
179 | } else {
180 | finishKey(key, OPEN);
181 | }
182 | }
183 | }
184 |
185 | } catch (ConnectException e) {
186 | if (e.getMessage().equals(E_REFUSED)) {
187 | finishKey(key, CLOSED);
188 | } else if (e.getMessage().equals(E_TIMEOUT)) {
189 | finishKey(key, FILTERED);
190 | } else {
191 | Log.e(TAG, e.getMessage());
192 | e.printStackTrace();
193 | finishKey(key, FILTERED);
194 | }
195 | } catch (Exception e) {
196 | try {
197 | Log.e(TAG, e.getMessage());
198 | } catch (java.lang.NullPointerException e1) {
199 | e1.printStackTrace();
200 | } finally {
201 | e.printStackTrace();
202 | finishKey(key, FILTERED);
203 | }
204 | } finally {
205 | iterator.remove();
206 | }
207 | }
208 | }
209 | } else {
210 | // Remove old/non-connected keys
211 | final long now = System.nanoTime();
212 | final Iterator iterator = selector.keys().iterator();
213 | while (iterator.hasNext()) {
214 | final SelectionKey key = (SelectionKey) iterator.next();
215 | final Data data = (Data) key.attachment();
216 | if (data.state == OPEN && now - data.start > TIMEOUT_RW) {
217 | Log.e(TAG, "TIMEOUT=" + data.port);
218 | finishKey(key, TIMEOUT);
219 | } else if (data.state != OPEN && now - data.start > TIMEOUT_CONNECT) {
220 | finishKey(key, TIMEOUT);
221 | }
222 | }
223 | }
224 | }
225 | } catch (IOException e) {
226 | Log.e(TAG, e.getMessage());
227 | } finally {
228 | closeSelector();
229 | }
230 | }
231 |
232 | private void connectSocket(InetAddress ina, int port) {
233 | // Create the socket
234 | try {
235 | SocketChannel socket = SocketChannel.open();
236 | socket.configureBlocking(false);
237 | socket.connect(new InetSocketAddress(ina, port));
238 | Data data = new Data();
239 | data.port = port;
240 | data.start = System.nanoTime();
241 | socket.register(selector, SelectionKey.OP_CONNECT, data);
242 | } catch (IOException e) {
243 | Log.e(TAG, e.getMessage());
244 | }
245 | }
246 |
247 | protected void onCancelled() {
248 | select = false;
249 | }
250 |
251 | private void closeSelector() {
252 | try {
253 | if (selector.isOpen()) {
254 | synchronized (selector.keys()) {
255 | Iterator iterator = selector.keys().iterator();
256 | while (iterator.hasNext()) {
257 | finishKey((SelectionKey) iterator.next(), FILTERED);
258 | }
259 | selector.close();
260 | }
261 | }
262 | } catch (IOException e) {
263 | Log.e(TAG, e.getMessage());
264 | } catch (ClosedSelectorException e) {
265 | if (e.getMessage() != null) {
266 | Log.e(TAG, e.getMessage());
267 | }
268 | }
269 | }
270 |
271 | private void finishKey(SelectionKey key, int state) {
272 | finishKey(key, state, null);
273 | }
274 |
275 | private void finishKey(SelectionKey key, int state, String banner) {
276 | synchronized (key) {
277 | if(key == null || !key.isValid()){
278 | return;
279 | }
280 | closeChannel(key.channel());
281 | Data data = (Data) key.attachment();
282 | publishProgress(data.port, state, banner);
283 | key.attach(null);
284 | key.cancel();
285 | key = null;
286 | }
287 | }
288 |
289 | private void closeChannel(SelectableChannel channel) {
290 | if (channel instanceof SocketChannel) {
291 | Socket socket = ((SocketChannel) channel).socket();
292 | try{
293 | if (!socket.isInputShutdown()) socket.shutdownInput();
294 | } catch (IOException ex){
295 | }
296 | try{
297 | if (!socket.isOutputShutdown()) socket.shutdownOutput();
298 | } catch (IOException ex){
299 | }
300 | try{
301 | socket.close();
302 | } catch (IOException ex){
303 | }
304 | }
305 | try{
306 | channel.close();
307 | } catch (IOException ex){
308 | }
309 | }
310 |
311 | // Port private object
312 | private static class Data {
313 | protected int state = FILTERED;
314 | protected int port;
315 | protected long start;
316 | protected int pass = 0;
317 | }
318 | }
319 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/DefaultDiscovery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network;
7 |
8 | import info.lamatricexiste.network.Network.HardwareAddress;
9 | import info.lamatricexiste.network.Network.HostBean;
10 | import info.lamatricexiste.network.Network.NetInfo;
11 | import info.lamatricexiste.network.Network.Ping;
12 | import info.lamatricexiste.network.Network.RateControl;
13 | import info.lamatricexiste.network.Utils.Prefs;
14 | import info.lamatricexiste.network.Utils.Save;
15 |
16 | import java.io.IOException;
17 | import java.lang.IllegalArgumentException;
18 | import java.net.InetSocketAddress;
19 | import java.net.InetAddress;
20 | import java.net.UnknownHostException;
21 | import java.net.Socket;
22 | import java.util.concurrent.ExecutorService;
23 | import java.util.concurrent.Executors;
24 | import java.util.concurrent.TimeUnit;
25 |
26 | import android.content.SharedPreferences.Editor;
27 | import android.database.sqlite.SQLiteDatabaseCorruptException;
28 | import android.util.Log;
29 |
30 | public class DefaultDiscovery extends AbstractDiscovery {
31 |
32 | private final String TAG = "DefaultDiscovery";
33 | private final static int[] DPORTS = { 139, 445, 22, 80 };
34 | private final static int TIMEOUT_SCAN = 3600; // seconds
35 | private final static int TIMEOUT_SHUTDOWN = 10; // seconds
36 | private final static int THREADS = 10; //FIXME: Test, plz set in options again ?
37 | private final int mRateMult = 5; // Number of alive hosts between Rate
38 | private int pt_move = 2; // 1=backward 2=forward
39 | private ExecutorService mPool;
40 | private boolean doRateControl;
41 | private RateControl mRateControl;
42 | private Save mSave;
43 |
44 | public DefaultDiscovery(ActivityDiscovery discover) {
45 | super(discover);
46 | mRateControl = new RateControl();
47 | mSave = new Save();
48 | }
49 |
50 | @Override
51 | protected void onPreExecute() {
52 | super.onPreExecute();
53 | if (mDiscover != null) {
54 | final ActivityDiscovery discover = mDiscover.get();
55 | if (discover != null) {
56 | doRateControl = discover.prefs.getBoolean(Prefs.KEY_RATECTRL_ENABLE,
57 | Prefs.DEFAULT_RATECTRL_ENABLE);
58 | }
59 | }
60 | }
61 |
62 | @Override
63 | protected Void doInBackground(Void... params) {
64 | if (mDiscover != null) {
65 | final ActivityDiscovery discover = mDiscover.get();
66 | if (discover != null) {
67 | Log.v(TAG, "start=" + NetInfo.getIpFromLongUnsigned(start) + " (" + start
68 | + "), end=" + NetInfo.getIpFromLongUnsigned(end) + " (" + end
69 | + "), length=" + size);
70 | mPool = Executors.newFixedThreadPool(THREADS);
71 | if (ip <= end && ip >= start) {
72 | Log.i(TAG, "Back and forth scanning");
73 | // gateway
74 | launch(start);
75 |
76 | // hosts
77 | long pt_backward = ip;
78 | long pt_forward = ip + 1;
79 | long size_hosts = size - 1;
80 |
81 | for (int i = 0; i < size_hosts; i++) {
82 | // Set pointer if of limits
83 | if (pt_backward <= start) {
84 | pt_move = 2;
85 | } else if (pt_forward > end) {
86 | pt_move = 1;
87 | }
88 | // Move back and forth
89 | if (pt_move == 1) {
90 | launch(pt_backward);
91 | pt_backward--;
92 | pt_move = 2;
93 | } else if (pt_move == 2) {
94 | launch(pt_forward);
95 | pt_forward++;
96 | pt_move = 1;
97 | }
98 | }
99 | } else {
100 | Log.i(TAG, "Sequencial scanning");
101 | for (long i = start; i <= end; i++) {
102 | launch(i);
103 | }
104 | }
105 | mPool.shutdown();
106 | try {
107 | if(!mPool.awaitTermination(TIMEOUT_SCAN, TimeUnit.SECONDS)){
108 | mPool.shutdownNow();
109 | Log.e(TAG, "Shutting down pool");
110 | if(!mPool.awaitTermination(TIMEOUT_SHUTDOWN, TimeUnit.SECONDS)){
111 | Log.e(TAG, "Pool did not terminate");
112 | }
113 | }
114 | } catch (InterruptedException e){
115 | Log.e(TAG, e.getMessage());
116 | mPool.shutdownNow();
117 | Thread.currentThread().interrupt();
118 | } finally {
119 | mSave.closeDb();
120 | }
121 | }
122 | }
123 | return null;
124 | }
125 |
126 | @Override
127 | protected void onCancelled() {
128 | if (mPool != null) {
129 | synchronized (mPool) {
130 | mPool.shutdownNow();
131 | // FIXME: Prevents some task to end (and close the Save DB)
132 | }
133 | }
134 | super.onCancelled();
135 | }
136 |
137 | private void launch(long i) {
138 | if(!mPool.isShutdown()) {
139 | mPool.execute(new CheckRunnable(NetInfo.getIpFromLongUnsigned(i)));
140 | }
141 | }
142 |
143 | private int getRate() {
144 | if (doRateControl) {
145 | return mRateControl.rate;
146 | }
147 |
148 | if (mDiscover != null) {
149 | final ActivityDiscovery discover = mDiscover.get();
150 | if (discover != null) {
151 | return Integer.parseInt(discover.prefs.getString(Prefs.KEY_TIMEOUT_DISCOVER,
152 | Prefs.DEFAULT_TIMEOUT_DISCOVER));
153 | }
154 | }
155 | return 1;
156 | }
157 |
158 | private class CheckRunnable implements Runnable {
159 | private String addr;
160 |
161 | CheckRunnable(String addr) {
162 | this.addr = addr;
163 | }
164 |
165 | public void run() {
166 | if(isCancelled()) {
167 | publish(null);
168 | }
169 | Log.e(TAG, "run="+addr);
170 | // Create host object
171 | final HostBean host = new HostBean();
172 | host.responseTime = getRate();
173 | host.ipAddress = addr;
174 | try {
175 | InetAddress h = InetAddress.getByName(addr);
176 | // Rate control check
177 | if (doRateControl && mRateControl.indicator != null && hosts_done % mRateMult == 0) {
178 | mRateControl.adaptRate();
179 | }
180 | // Arp Check #1
181 | host.hardwareAddress = HardwareAddress.getHardwareAddress(addr);
182 | if(!NetInfo.NOMAC.equals(host.hardwareAddress)){
183 | Log.e(TAG, "found using arp #1 "+addr);
184 | publish(host);
185 | return;
186 | }
187 | // Native InetAddress check
188 | if (h.isReachable(getRate())) {
189 | Log.e(TAG, "found using InetAddress ping "+addr);
190 | publish(host);
191 | // Set indicator and get a rate
192 | if (doRateControl && mRateControl.indicator == null) {
193 | mRateControl.indicator = addr;
194 | mRateControl.adaptRate();
195 | }
196 | return;
197 | }
198 | // Arp Check #2
199 | host.hardwareAddress = HardwareAddress.getHardwareAddress(addr);
200 | if(!NetInfo.NOMAC.equals(host.hardwareAddress)){
201 | Log.e(TAG, "found using arp #2 "+addr);
202 | publish(host);
203 | return;
204 | }
205 | // Custom check
206 | int port;
207 | // TODO: Get ports from options
208 | Socket s = new Socket();
209 | for (int i = 0; i < DPORTS.length; i++) {
210 | try {
211 | s.bind(null);
212 | s.connect(new InetSocketAddress(addr, DPORTS[i]), getRate());
213 | Log.v(TAG, "found using TCP connect "+addr+" on port=" + DPORTS[i]);
214 | } catch (IOException e) {
215 | } catch (IllegalArgumentException e) {
216 | } finally {
217 | try {
218 | s.close();
219 | } catch (Exception e){
220 | }
221 | }
222 | }
223 |
224 | /*
225 | if ((port = Reachable.isReachable(h, getRate())) > -1) {
226 | Log.v(TAG, "used Network.Reachable object, "+addr+" port=" + port);
227 | publish(host);
228 | return;
229 | }
230 | */
231 | // Arp Check #3
232 | host.hardwareAddress = HardwareAddress.getHardwareAddress(addr);
233 | if(!NetInfo.NOMAC.equals(host.hardwareAddress)){
234 | Log.e(TAG, "found using arp #3 "+addr);
235 | publish(host);
236 | return;
237 | }
238 | publish(null);
239 |
240 | } catch (IOException e) {
241 | publish(null);
242 | Log.e(TAG, e.getMessage());
243 | }
244 | }
245 | }
246 |
247 | private void publish(final HostBean host) {
248 | hosts_done++;
249 | if(host == null){
250 | publishProgress((HostBean) null);
251 | return;
252 | }
253 |
254 | if (mDiscover != null) {
255 | final ActivityDiscovery discover = mDiscover.get();
256 | if (discover != null) {
257 | // Mac Addr not already detected
258 | if(NetInfo.NOMAC.equals(host.hardwareAddress)){
259 | host.hardwareAddress = HardwareAddress.getHardwareAddress(host.ipAddress);
260 | }
261 |
262 | // NIC vendor
263 | host.nicVendor = HardwareAddress.getNicVendor(host.hardwareAddress);
264 |
265 | // Is gateway ?
266 | if (discover.net.gatewayIp.equals(host.ipAddress)) {
267 | host.deviceType = HostBean.TYPE_GATEWAY;
268 | }
269 |
270 | // FQDN
271 | // Static
272 | if ((host.hostname = mSave.getCustomName(host)) == null) {
273 | // DNS
274 | if (discover.prefs.getBoolean(Prefs.KEY_RESOLVE_NAME,
275 | Prefs.DEFAULT_RESOLVE_NAME) == true) {
276 | try {
277 | host.hostname = (InetAddress.getByName(host.ipAddress)).getCanonicalHostName();
278 | } catch (UnknownHostException e) {
279 | Log.e(TAG, e.getMessage());
280 | }
281 | }
282 | // TODO: NETBIOS
283 | //try {
284 | // host.hostname = NbtAddress.getByName(addr).getHostName();
285 | //} catch (UnknownHostException e) {
286 | // Log.i(TAG, e.getMessage());
287 | //}
288 | }
289 | }
290 | }
291 |
292 | publishProgress(host);
293 | }
294 | }
295 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/DnsDiscovery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network;
7 |
8 | import info.lamatricexiste.network.Network.HardwareAddress;
9 | import info.lamatricexiste.network.Network.HostBean;
10 | import info.lamatricexiste.network.Network.NetInfo;
11 | import info.lamatricexiste.network.Utils.Prefs;
12 |
13 | import java.io.IOException;
14 | import java.net.InetAddress;
15 |
16 | import android.database.sqlite.SQLiteDatabaseCorruptException;
17 | import android.util.Log;
18 |
19 | public class DnsDiscovery extends AbstractDiscovery {
20 |
21 | private final String TAG = "DnsDiscovery";
22 |
23 | public DnsDiscovery(ActivityDiscovery discover) {
24 | super(discover);
25 | }
26 |
27 | @Override
28 | protected Void doInBackground(Void... params) {
29 | if (mDiscover != null) {
30 | final ActivityDiscovery discover = mDiscover.get();
31 | if (discover != null) {
32 | Log.i(TAG, "start=" + NetInfo.getIpFromLongUnsigned(start) + " (" + start
33 | + "), end=" + NetInfo.getIpFromLongUnsigned(end) + " (" + end
34 | + "), length=" + size);
35 |
36 | int timeout = Integer.parseInt(discover.prefs.getString(Prefs.KEY_TIMEOUT_DISCOVER,
37 | Prefs.DEFAULT_TIMEOUT_DISCOVER));
38 | Log.i(TAG, "timeout=" + timeout + "ms");
39 |
40 | for (long i = start; i < end + 1; i++) {
41 | hosts_done++;
42 | HostBean host = new HostBean();
43 | host.ipAddress = NetInfo.getIpFromLongUnsigned(i);
44 | try {
45 | InetAddress ia = InetAddress.getByName(host.ipAddress);
46 | host.hostname = ia.getCanonicalHostName();
47 | host.isAlive = ia.isReachable(timeout) ? 1 : 0;
48 | } catch (java.net.UnknownHostException e) {
49 | Log.e(TAG, e.getMessage());
50 | } catch (IOException e) {
51 | Log.e(TAG, e.getMessage());
52 | }
53 | if (host.hostname != null && !host.hostname.equals(host.ipAddress)) {
54 | // Is gateway ?
55 | if (discover.net.gatewayIp.equals(host.ipAddress)) {
56 | host.deviceType = 1;
57 | }
58 | // Mac Addr
59 | host.hardwareAddress = HardwareAddress.getHardwareAddress(host.ipAddress);
60 | // NIC vendor
61 | try {
62 | host.nicVendor = HardwareAddress.getNicVendor(host.hardwareAddress);
63 | } catch (SQLiteDatabaseCorruptException e) {
64 | Log.e(TAG, e.getMessage());
65 | }
66 | publishProgress(host);
67 | } else {
68 | publishProgress((HostBean) null);
69 | }
70 | }
71 | }
72 | }
73 | return null;
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Network/Banner.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network.Network;
7 |
8 | import java.io.BufferedReader;
9 | import java.io.IOException;
10 | import java.io.InputStreamReader;
11 | import java.net.InetSocketAddress;
12 | import java.net.Socket;
13 |
14 | import android.os.AsyncTask;
15 | import android.util.Log;
16 |
17 | public class Banner extends AsyncTask {
18 |
19 | private final String TAG = "Banner";
20 | private static final int BUF = 8 * 1024;
21 | private String host;
22 | private int port;
23 | private int timeout;
24 | private String banner = "";
25 |
26 | public Banner(String host, int port, int timeout) {
27 | this.host = host;
28 | this.port = port;
29 | this.timeout = timeout;
30 | }
31 |
32 | @Override
33 | protected Void doInBackground(Void... params) {
34 | try {
35 | Socket s = new Socket();
36 | s.bind(null);
37 | s.connect(new InetSocketAddress(host, port), timeout);
38 | BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()), BUF);
39 | while ((banner = in.readLine()) != null) {
40 | break;
41 | }
42 | in.close();
43 | s.close();
44 | Log.v(TAG, banner);
45 | return null;
46 | } catch (IOException e) {
47 | }
48 | return null;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Network/DownloadFile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | // Taken from: http://github.com/ctrlaltdel/TahoeLAFS-android
7 |
8 | package info.lamatricexiste.network.Network;
9 |
10 | import info.lamatricexiste.network.ActivityMain;
11 |
12 | import java.io.FileOutputStream;
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 | import java.net.UnknownHostException;
16 | import java.nio.ByteBuffer;
17 | import java.nio.channels.Channels;
18 | import java.nio.channels.ReadableByteChannel;
19 | import java.nio.channels.WritableByteChannel;
20 | import java.util.zip.GZIPInputStream;
21 |
22 | import javax.net.ssl.SSLException;
23 |
24 | import org.apache.http.HttpEntity;
25 | import org.apache.http.HttpResponse;
26 | import org.apache.http.client.ClientProtocolException;
27 | import org.apache.http.client.HttpClient;
28 | import org.apache.http.client.methods.HttpGet;
29 | import org.apache.http.impl.client.DefaultHttpClient;
30 |
31 | import android.content.Context;
32 | import android.content.pm.PackageManager.NameNotFoundException;
33 | import android.util.Log;
34 |
35 | public class DownloadFile {
36 |
37 | private static String TAG = "DownloadFile";
38 | private final String USERAGENT = "Android/" + android.os.Build.VERSION.RELEASE + " ("
39 | + android.os.Build.MODEL + ") NetworkDiscovery/";
40 | private HttpClient httpclient;
41 |
42 | public DownloadFile(final Context ctxt, String url, FileOutputStream out) throws IOException, NullPointerException {
43 | String version = "0.3.x";
44 | try {
45 | version = ctxt.getPackageManager().getPackageInfo(ActivityMain.TAG, 0).versionName;
46 | } catch (NameNotFoundException e) {
47 | }
48 |
49 | httpclient = new DefaultHttpClient();
50 | httpclient.getParams().setParameter("http.useragent", USERAGENT + version);
51 | InputStream in = openURL(url);
52 | if(in == null){
53 | Log.e(TAG, "Unable to download: " + url);
54 | return;
55 | }
56 |
57 | final ReadableByteChannel inputChannel = Channels.newChannel(in);
58 | final WritableByteChannel outputChannel = Channels.newChannel(out);
59 |
60 | try {
61 | Log.i(TAG, "Downloading " + url);
62 | fastChannelCopy(inputChannel, outputChannel);
63 | } finally {
64 | try {
65 | if (inputChannel != null) {
66 | inputChannel.close();
67 | }
68 | if (outputChannel != null) {
69 | outputChannel.close();
70 | }
71 | if (in != null) {
72 | in.close();
73 | }
74 | if (out != null) {
75 | out.close();
76 | }
77 | } catch (Exception e) {
78 | if (e != null && e.getMessage() != null) {
79 | Log.e(TAG, e.getMessage());
80 | } else {
81 | Log.e(TAG, "fastChannelCopy() unknown error");
82 | }
83 | }
84 | }
85 | }
86 |
87 | private InputStream openURL(String url) {
88 | HttpGet httpget = new HttpGet(url);
89 | HttpResponse response;
90 | try {
91 | try {
92 | response = httpclient.execute(httpget);
93 | } catch (SSLException e) {
94 | Log.i(TAG, "SSL Certificate is not trusted");
95 | response = httpclient.execute(httpget);
96 | }
97 | Log.i(TAG, "Status:[" + response.getStatusLine().toString() + "]");
98 | HttpEntity entity = response.getEntity();
99 |
100 | if (entity != null) {
101 | return new GZIPInputStream(entity.getContent());
102 | }
103 | } catch (ClientProtocolException e) {
104 | Log.e(TAG, "There was a protocol based error", e);
105 | } catch (UnknownHostException e) {
106 | Log.e(TAG, e.getMessage());
107 | } catch (IOException e) {
108 | Log.e(TAG, "There was an IO Stream related error", e);
109 | }
110 |
111 | return null;
112 | }
113 |
114 | public static void fastChannelCopy(final ReadableByteChannel src, final WritableByteChannel dest)
115 | throws IOException, NullPointerException {
116 | if (src != null && dest != null) {
117 | final ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024);
118 | while (src.read(buffer) != -1) {
119 | // prepare the buffer to be drained
120 | buffer.flip();
121 | // write to the channel, may block
122 | dest.write(buffer);
123 | // If partial transfer, shift remainder down
124 | // If buffer is empty, same as doing clear()
125 | buffer.compact();
126 | }
127 | // EOF will leave buffer in fill state
128 | buffer.flip();
129 | // make sure the buffer is fully drained.
130 | while (buffer.hasRemaining()) {
131 | dest.write(buffer);
132 | }
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Network/HardwareAddress.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | // http://standards.ieee.org/regauth/oui/oui.txt
7 |
8 | package info.lamatricexiste.network.Network;
9 |
10 | import info.lamatricexiste.network.R;
11 | import info.lamatricexiste.network.Utils.Prefs;
12 | import info.lamatricexiste.network.Utils.Db;
13 |
14 | import java.io.BufferedReader;
15 | import java.io.FileReader;
16 | import java.io.IOException;
17 | import java.lang.ref.WeakReference;
18 | import java.util.regex.Matcher;
19 | import java.util.regex.Pattern;
20 |
21 | import android.app.Activity;
22 | import android.content.Context;
23 | import android.content.SharedPreferences.Editor;
24 | import android.database.Cursor;
25 | import android.database.sqlite.SQLiteDatabase;
26 | import android.database.sqlite.SQLiteException;
27 | import android.database.sqlite.SQLiteDatabaseCorruptException;
28 | import android.preference.PreferenceManager;
29 | import android.util.Log;
30 |
31 | public class HardwareAddress {
32 |
33 | private final static String TAG = "HardwareAddress";
34 | private final static String REQ = "select vendor from oui where mac=?";
35 | // 0x1 is HW Type: Ethernet (10Mb) [JBP]
36 | // 0x2 is ARP Flag: completed entry (ha valid)
37 | private final static String MAC_RE = "^%s\\s+0x1\\s+0x2\\s+([:0-9a-fA-F]+)\\s+\\*\\s+\\w+$";
38 | private final static int BUF = 8 * 1024;
39 | private WeakReference mActivity;
40 |
41 | public HardwareAddress(Activity activity) {
42 | }
43 |
44 | public static String getHardwareAddress(String ip) {
45 | String hw = NetInfo.NOMAC;
46 | BufferedReader bufferedReader = null;
47 | try {
48 | if (ip != null) {
49 | String ptrn = String.format(MAC_RE, ip.replace(".", "\\."));
50 | Pattern pattern = Pattern.compile(ptrn);
51 | bufferedReader = new BufferedReader(new FileReader("/proc/net/arp"), BUF);
52 | String line;
53 | Matcher matcher;
54 | while ((line = bufferedReader.readLine()) != null) {
55 | matcher = pattern.matcher(line);
56 | if (matcher.matches()) {
57 | hw = matcher.group(1);
58 | break;
59 | }
60 | }
61 | } else {
62 | Log.e(TAG, "ip is null");
63 | }
64 | } catch (IOException e) {
65 | Log.e(TAG, "Can't open/read file ARP: " + e.getMessage());
66 | return hw;
67 | } finally {
68 | try {
69 | if(bufferedReader != null) {
70 | bufferedReader.close();
71 | }
72 | } catch (IOException e) {
73 | Log.e(TAG, e.getMessage());
74 | }
75 | }
76 | return hw;
77 | }
78 |
79 | public static String getNicVendor(String hw) throws SQLiteDatabaseCorruptException {
80 | String ni = null;
81 | try {
82 | SQLiteDatabase db = SQLiteDatabase.openDatabase(Db.PATH + Db.DB_NIC, null, SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
83 | if (db != null) {
84 | // Db request
85 | if (db.isOpen()) {
86 | Cursor c = db.rawQuery(REQ, new String[] { hw.replace(":", "")
87 | .substring(0, 6).toUpperCase() });
88 | if (c.moveToFirst()) {
89 | ni = c.getString(0);
90 | }
91 | c.close();
92 | }
93 | db.close();
94 | }
95 | } catch (IllegalStateException e) {
96 | Log.e(TAG, e.getMessage());
97 | } catch (SQLiteException e) {
98 | Log.e(TAG, e.getMessage());
99 | // FIXME: Reset db
100 | //Context ctxt = d.getApplicationContext();
101 | //Editor edit = PreferenceManager.getDefaultSharedPreferences(ctxt).edit();
102 | //edit.putInt(Prefs.KEY_RESET_NICDB, 1);
103 | //edit.commit();
104 | }
105 | return ni;
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Network/HostBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | // Inspired by http://connectbot.googlecode.com/svn/trunk/connectbot/src/org/connectbot/bean/HostBean.java
7 | package info.lamatricexiste.network.Network;
8 |
9 | import info.lamatricexiste.network.ActivityMain;
10 |
11 | import java.util.ArrayList;
12 | import java.util.HashMap;
13 |
14 | import android.os.Parcel;
15 | import android.os.Parcelable;
16 |
17 | public class HostBean implements Parcelable {
18 |
19 | public static final String EXTRA = ActivityMain.PKG + ".extra";
20 | public static final String EXTRA_POSITION = ActivityMain.PKG + ".extra_position";
21 | public static final String EXTRA_HOST = ActivityMain.PKG + ".extra_host";
22 | public static final String EXTRA_TIMEOUT = ActivityMain.PKG + ".network.extra_timeout";
23 | public static final String EXTRA_HOSTNAME = ActivityMain.PKG + ".extra_hostname";
24 | public static final String EXTRA_BANNERS = ActivityMain.PKG + ".extra_banners";
25 | public static final String EXTRA_PORTSO = ActivityMain.PKG + ".extra_ports_o";
26 | public static final String EXTRA_PORTSC = ActivityMain.PKG + ".extra_ports_c";
27 | public static final String EXTRA_SERVICES = ActivityMain.PKG + ".extra_services";
28 | public static final int TYPE_GATEWAY = 0;
29 | public static final int TYPE_COMPUTER = 1;
30 |
31 | public int deviceType = TYPE_COMPUTER;
32 | public int isAlive = 1;
33 | public int position = 0;
34 | public int responseTime = 0; // ms
35 | public String ipAddress = null;
36 | public String hostname = null;
37 | public String hardwareAddress = NetInfo.NOMAC;
38 | public String nicVendor = "Unknown";
39 | public String os = "Unknown";
40 | public HashMap services = null;
41 | public HashMap banners = null;
42 | public ArrayList portsOpen = null;
43 | public ArrayList portsClosed = null;
44 |
45 | public HostBean() {
46 | // New object
47 | }
48 |
49 | public HostBean(Parcel in) {
50 | // Object from parcel
51 | readFromParcel(in);
52 | }
53 |
54 | public int describeContents() {
55 | return 0;
56 | }
57 |
58 | public void writeToParcel(Parcel dest, int flags) {
59 | dest.writeInt(deviceType);
60 | dest.writeInt(isAlive);
61 | dest.writeString(ipAddress);
62 | dest.writeString(hostname);
63 | dest.writeString(hardwareAddress);
64 | dest.writeString(nicVendor);
65 | dest.writeString(os);
66 | dest.writeInt(responseTime);
67 | dest.writeInt(position);
68 | dest.writeMap(services);
69 | dest.writeMap(banners);
70 | dest.writeList(portsOpen);
71 | dest.writeList(portsClosed);
72 | }
73 |
74 | @SuppressWarnings("unchecked")
75 | private void readFromParcel(Parcel in) {
76 | deviceType = in.readInt();
77 | isAlive = in.readInt();
78 | ipAddress = in.readString();
79 | hostname = in.readString();
80 | hardwareAddress = in.readString();
81 | nicVendor = in.readString();
82 | os = in.readString();
83 | responseTime = in.readInt();
84 | position = in.readInt();
85 | services = in.readHashMap(null);
86 | banners = in.readHashMap(null);
87 | portsOpen = in.readArrayList(Integer.class.getClassLoader());
88 | portsClosed = in.readArrayList(Integer.class.getClassLoader());
89 | }
90 |
91 | @SuppressWarnings("unchecked")
92 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
93 | public HostBean createFromParcel(Parcel in) {
94 | return new HostBean(in);
95 | }
96 |
97 | public HostBean[] newArray(int size) {
98 | return new HostBean[size];
99 | }
100 | };
101 | }
102 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Network/NetInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | //am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings
7 | package info.lamatricexiste.network.Network;
8 |
9 | import info.lamatricexiste.network.Utils.Prefs;
10 |
11 | import java.io.BufferedReader;
12 | import java.io.File;
13 | import java.io.InputStreamReader;
14 | import java.net.Inet6Address;
15 | import java.net.InetAddress;
16 | import java.net.NetworkInterface;
17 | import java.net.SocketException;
18 | import java.util.Enumeration;
19 | import java.util.regex.Matcher;
20 | import java.util.regex.Pattern;
21 |
22 | import android.content.Context;
23 | import android.content.SharedPreferences;
24 | import android.content.SharedPreferences.Editor;
25 | import android.net.ConnectivityManager;
26 | import android.net.NetworkInfo;
27 | import android.net.wifi.SupplicantState;
28 | import android.net.wifi.WifiInfo;
29 | import android.net.wifi.WifiManager;
30 | import android.preference.PreferenceManager;
31 | import android.telephony.TelephonyManager;
32 | import android.util.Log;
33 |
34 | // TODO: IPv6 support
35 |
36 | public class NetInfo {
37 | private final String TAG = "NetInfo";
38 | private static final int BUF = 8 * 1024;
39 | private static final String CMD_IP = " -f inet addr show %s";
40 | private static final String PTN_IP1 = "\\s*inet [0-9\\.]+\\/([0-9]+) brd [0-9\\.]+ scope global %s$";
41 | private static final String PTN_IP2 = "\\s*inet [0-9\\.]+ peer [0-9\\.]+\\/([0-9]+) scope global %s$"; // FIXME: Merge with PTN_IP1
42 | private static final String PTN_IF = "^%s: ip [0-9\\.]+ mask ([0-9\\.]+) flags.*";
43 | private static final String NOIF = "0";
44 | public static final String NOIP = "0.0.0.0";
45 | public static final String NOMASK = "255.255.255.255";
46 | public static final String NOMAC = "00:00:00:00:00:00";
47 | private Context ctxt;
48 | private WifiInfo info;
49 | private SharedPreferences prefs;
50 |
51 | public String intf = "eth0";
52 | public String ip = NOIP;
53 | public int cidr = 24;
54 |
55 | public int speed = 0;
56 | public String ssid = null;
57 | public String bssid = null;
58 | public String carrier = null;
59 | public String macAddress = NOMAC;
60 | public String netmaskIp = NOMASK;
61 | public String gatewayIp = NOIP;
62 |
63 | public NetInfo(final Context ctxt) {
64 | this.ctxt = ctxt;
65 | prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
66 | getIp();
67 | getWifiInfo();
68 |
69 | // Set ARP enabled
70 | // try {
71 | // Runtime.getRuntime().exec("su -C ip link set dev " + intf +
72 | // " arp on");
73 | // } catch (Exception e) {
74 | // Log.e(TAG, e.getMessage());
75 | // }
76 | // Runtime.getRuntime().exec("echo 1 > /proc/sys/net/ipv4/conf/" + intf
77 | // + "/proxy_arp");
78 | // Runtime.getRuntime().exec("echo 1 > /proc/sys/net/ipv4/conf/tun0/proxy_arp");
79 | }
80 |
81 | @Override
82 | public int hashCode() {
83 | int ip_custom = prefs.getBoolean(Prefs.KEY_IP_CUSTOM, Prefs.DEFAULT_IP_CUSTOM) ? 1:0;
84 | int ip_start = prefs.getString(Prefs.KEY_IP_START, Prefs.DEFAULT_IP_START).hashCode();
85 | int ip_end = prefs.getString(Prefs.KEY_IP_END, Prefs.DEFAULT_IP_END).hashCode();
86 | int cidr_custom = prefs.getBoolean(Prefs.KEY_CIDR_CUSTOM, Prefs.DEFAULT_CIDR_CUSTOM) ? 1:0;
87 | int cidr = prefs.getString(Prefs.KEY_CIDR, Prefs.DEFAULT_CIDR).hashCode();
88 | return 42 + intf.hashCode() + ip.hashCode() + cidr + ip_custom + ip_start + ip_end + cidr_custom + cidr;
89 | }
90 |
91 | public void getIp() {
92 | intf = prefs.getString(Prefs.KEY_INTF, Prefs.DEFAULT_INTF);
93 | try {
94 | if (intf == Prefs.DEFAULT_INTF || NOIF.equals(intf)) {
95 | // Automatic interface selection
96 | for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en
97 | .hasMoreElements();) {
98 | NetworkInterface ni = en.nextElement();
99 | intf = ni.getName();
100 | ip = getInterfaceFirstIp(ni);
101 | if (ip != NOIP) {
102 | break;
103 | }
104 | }
105 | } else {
106 | // Defined interface from Prefs
107 | ip = getInterfaceFirstIp(NetworkInterface.getByName(intf));
108 | }
109 | } catch (SocketException e) {
110 | Log.e(TAG, e.getMessage());
111 | //Editor edit = prefs.edit();
112 | //edit.putString(Prefs.KEY_INTF, Prefs.DEFAULT_INTF);
113 | //edit.commit();
114 | }
115 | getCidr();
116 | }
117 |
118 | private String getInterfaceFirstIp(NetworkInterface ni) {
119 | if (ni != null) {
120 | for (Enumeration nis = ni.getInetAddresses(); nis.hasMoreElements();) {
121 | InetAddress ia = nis.nextElement();
122 | if (!ia.isLoopbackAddress()) {
123 | if (ia instanceof Inet6Address) {
124 | Log.i(TAG, "IPv6 detected and not supported yet!");
125 | continue;
126 | }
127 | return ia.getHostAddress();
128 | }
129 | }
130 | }
131 | return NOIP;
132 | }
133 |
134 | private void getCidr() {
135 | if (netmaskIp != NOMASK) {
136 | cidr = IpToCidr(netmaskIp);
137 | } else {
138 | String match;
139 | // Running ip tools
140 | try {
141 | if ((match = runCommand("/system/xbin/ip", String.format(CMD_IP, intf), String.format(PTN_IP1, intf))) != null) {
142 | cidr = Integer.parseInt(match);
143 | return;
144 | } else if ((match = runCommand("/system/xbin/ip", String.format(CMD_IP, intf), String.format(PTN_IP2, intf))) != null) {
145 | cidr = Integer.parseInt(match);
146 | return;
147 | } else if ((match = runCommand("/system/bin/ifconfig", " " + intf, String.format(PTN_IF, intf))) != null) {
148 | cidr = IpToCidr(match);
149 | return;
150 | } else {
151 | Log.i(TAG, "cannot find cidr, using default /24");
152 | }
153 | } catch (NumberFormatException e) {
154 | Log.i(TAG, e.getMessage()+ " -> cannot find cidr, using default /24");
155 | }
156 | }
157 | }
158 |
159 | // FIXME: Factorize, this isn't a generic runCommand()
160 | private String runCommand(String path, String cmd, String ptn) {
161 | try {
162 | if (new File(path).exists() == true) {
163 | String line;
164 | Matcher matcher;
165 | Pattern ptrn = Pattern.compile(ptn);
166 | Process p = Runtime.getRuntime().exec(path + cmd);
167 | BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()), BUF);
168 | while ((line = r.readLine()) != null) {
169 | matcher = ptrn.matcher(line);
170 | if (matcher.matches()) {
171 | return matcher.group(1);
172 | }
173 | }
174 | }
175 | } catch (Exception e) {
176 | Log.e(TAG, "Can't use native command: " + e.getMessage());
177 | return null;
178 | }
179 | return null;
180 | }
181 |
182 | public boolean getMobileInfo() {
183 | TelephonyManager tm = (TelephonyManager) ctxt.getSystemService(Context.TELEPHONY_SERVICE);
184 | if (tm != null) {
185 | carrier = tm.getNetworkOperatorName();
186 | }
187 | return false;
188 | }
189 |
190 | public boolean getWifiInfo() {
191 | WifiManager wifi = (WifiManager) ctxt.getSystemService(Context.WIFI_SERVICE);
192 | if (wifi != null) {
193 | info = wifi.getConnectionInfo();
194 | // Set wifi variables
195 | speed = info.getLinkSpeed();
196 | ssid = info.getSSID();
197 | bssid = info.getBSSID();
198 | macAddress = info.getMacAddress();
199 | gatewayIp = getIpFromIntSigned(wifi.getDhcpInfo().gateway);
200 | // broadcastIp = getIpFromIntSigned((dhcp.ipAddress & dhcp.netmask)
201 | // | ~dhcp.netmask);
202 | netmaskIp = getIpFromIntSigned(wifi.getDhcpInfo().netmask);
203 | return true;
204 | }
205 | return false;
206 | }
207 |
208 | public String getNetIp() {
209 | int shift = (32 - cidr);
210 | int start = ((int) getUnsignedLongFromIp(ip) >> shift << shift);
211 | return getIpFromLongUnsigned((long) start);
212 | }
213 |
214 | /*
215 | * public String getIp() { return getIpFromIntSigned(dhcp.ipAddress); }
216 | * public int getNetCidr() { int i = dhcp.netmask; i = i - ((i >> 1) &
217 | * 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); return ((i +
218 | * (i >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // return 24; } public String
219 | * getNetIp() { return getIpFromIntSigned(dhcp.ipAddress & dhcp.netmask); }
220 | */
221 | // public String getNetmask() {
222 | // return getIpFromIntSigned(dhcp.netmask);
223 | // }
224 |
225 | // public String getBroadcastIp() {
226 | // return getIpFromIntSigned((dhcp.ipAddress & dhcp.netmask) |
227 | // ~dhcp.netmask);
228 | // }
229 |
230 | // public Object getGatewayIp() {
231 | // return getIpFromIntSigned(dhcp.gateway);
232 | // }
233 |
234 | public SupplicantState getSupplicantState() {
235 | return info.getSupplicantState();
236 | }
237 |
238 | public static boolean isConnected(Context ctxt) {
239 | NetworkInfo nfo = ((ConnectivityManager) ctxt
240 | .getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
241 | if (nfo != null) {
242 | return nfo.isConnected();
243 | }
244 | return false;
245 | }
246 |
247 | public static long getUnsignedLongFromIp(String ip_addr) {
248 | String[] a = ip_addr.split("\\.");
249 | return (Integer.parseInt(a[0]) * 16777216 + Integer.parseInt(a[1]) * 65536
250 | + Integer.parseInt(a[2]) * 256 + Integer.parseInt(a[3]));
251 | }
252 |
253 | public static String getIpFromIntSigned(int ip_int) {
254 | String ip = "";
255 | for (int k = 0; k < 4; k++) {
256 | ip = ip + ((ip_int >> k * 8) & 0xFF) + ".";
257 | }
258 | return ip.substring(0, ip.length() - 1);
259 | }
260 |
261 | public static String getIpFromLongUnsigned(long ip_long) {
262 | String ip = "";
263 | for (int k = 3; k > -1; k--) {
264 | ip = ip + ((ip_long >> k * 8) & 0xFF) + ".";
265 | }
266 | return ip.substring(0, ip.length() - 1);
267 | }
268 |
269 | private int IpToCidr(String ip) {
270 | double sum = -2;
271 | String[] part = ip.split("\\.");
272 | for (String p : part) {
273 | sum += 256D - Double.parseDouble(p);
274 | }
275 | return 32 - (int) (Math.log(sum) / Math.log(2d));
276 | }
277 |
278 | // public int getIntFromInet(InetAddress ip_addr) {
279 | // return getIntFromIp(ip_addr.getHostAddress());
280 | // }
281 |
282 | // private InetAddress getInetFromInt(int ip_int) {
283 | // byte[] quads = new byte[4];
284 | // for (int k = 0; k < 4; k++)
285 | // quads[k] = (byte) ((ip_int >> k * 8) & 0xFF); // 0xFF=255
286 | // try {
287 | // return InetAddress.getByAddress(quads);
288 | // } catch (java.net.UnknownHostException e) {
289 | // return null;
290 | // }
291 | // }
292 | }
293 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Network/OsFingerprint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network.Network;
7 |
8 | public class OsFingerprint {
9 |
10 | // private final static String TAG = "OsFingerprint";
11 |
12 | public static String finger(long[] longArray) {
13 | return null;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Network/Ping.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network.Network;
7 |
8 | import java.net.InetAddress;
9 |
10 | import android.util.Log;
11 |
12 | public class Ping {
13 |
14 | private static final String TAG = "Ping";
15 | private static final String CMD = "/system/bin/ping -q -n -w 1 -c 1 %s";
16 | private static final int TIMEOUT = 1000;
17 |
18 | public static void doPing(String host) {
19 | try {
20 | // TODO: Use ProcessBuilder ?
21 | Runtime.getRuntime().exec(String.format(CMD, host));
22 | } catch (Exception e) {
23 | Log.e(TAG, "Can't use native ping: " + e.getMessage());
24 | try {
25 | if (InetAddress.getByName(host).isReachable(TIMEOUT)) {
26 | Log.i(TAG, "Using Java ICMP request instead ...");
27 | }
28 | } catch (Exception e1) {
29 | Log.e(TAG, e1.getMessage());
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Network/RateControl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network.Network;
7 |
8 | import java.io.BufferedReader;
9 | import java.io.IOException;
10 | import java.io.InputStreamReader;
11 | import java.net.InetAddress;
12 | import java.util.regex.Matcher;
13 | import java.util.regex.Pattern;
14 |
15 | import android.util.Log;
16 |
17 | public class RateControl {
18 |
19 | private final String TAG = "RateControl";
20 | private static final int BUF = 512;
21 | private final int REACH_TIMEOUT = 5000;
22 | private final String CMD = "/system/bin/ping -A -q -n -w 3 -W 2 -c 3 ";
23 | private final String PTN = "^rtt min\\/avg\\/max\\/mdev = [0-9\\.]+\\/[0-9\\.]+\\/([0-9\\.]+)\\/[0-9\\.]+ ms.*";
24 | private Pattern mPattern;
25 | private String line;
26 | public String indicator = null;
27 | public int rate = 800; // Slow start
28 |
29 | public RateControl() {
30 | mPattern = Pattern.compile(PTN);
31 | }
32 |
33 | public void adaptRate() {
34 | int response_time = 0;
35 | if ((response_time = getAvgResponseTime(indicator)) > 0) {
36 | if (response_time > 100) { // Most distanced hosts
37 | rate = response_time * 5; // Minimum 500ms
38 | } else {
39 | rate = response_time * 10; // Maximum 1000ms
40 | }
41 | if (rate > REACH_TIMEOUT) {
42 | rate = REACH_TIMEOUT;
43 | }
44 | }
45 | }
46 |
47 | private int getAvgResponseTime(String host) {
48 | // TODO: Reduce allocation
49 | BufferedReader reader = null;
50 | Matcher matcher;
51 | try {
52 | final Process proc = Runtime.getRuntime().exec(CMD + host);
53 | reader = new BufferedReader(new InputStreamReader(proc.getInputStream()), BUF);
54 | while ((line = reader.readLine()) != null) {
55 | matcher = mPattern.matcher(line);
56 | if (matcher.matches()) {
57 | reader.close();
58 | return (int) Float.parseFloat(matcher.group(1));
59 | }
60 | }
61 | reader.close();
62 | } catch (Exception e) {
63 | Log.e(TAG, "Can't use native ping: " + e.getMessage());
64 | try {
65 | final long start = System.nanoTime();
66 | if (InetAddress.getByName(host).isReachable(REACH_TIMEOUT)) {
67 | Log.i(TAG, "Using Java ICMP request instead ...");
68 | return (int) ((System.nanoTime() - start) / 1000);
69 | }
70 | } catch (Exception e1) {
71 | Log.e(TAG, e1.getMessage());
72 | }
73 | } finally {
74 | try {
75 | if (reader != null) {
76 | reader.close();
77 | }
78 | } catch(IOException e){
79 | }
80 | }
81 | return rate;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Network/SendSmbNegotiate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | /*
7 | ACKNOWLEDGE:
8 | This program was first to test MS 975497 SMB negotiate vuln, ported to java, to test against my own network.
9 | So there are still some traces of it in the code, and it could become a feature in the future..
10 |
11 | http://g-laurent.blogspot.com/2009/09/windows-vista7-smb20-negotiate-protocol.html
12 | */
13 |
14 | package info.lamatricexiste.network.Network;
15 |
16 | import java.io.IOException;
17 | import java.io.OutputStream;
18 | import java.net.InetAddress;
19 | import java.net.InetSocketAddress;
20 | import java.net.Socket;
21 |
22 | import android.util.Log;
23 |
24 | public class SendSmbNegotiate implements Runnable {
25 | private final String TAG = "SendSmbNegociate";
26 | private final int[] buff = { 0x00, 0x00, 0x00, 0x90, 0xff, 0x53, 0x4d, 0x42, 0x72, 0x00, 0x00,
27 | 0x00, 0x00, 0x18, 0x53, 0xc8, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
28 | 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x00,
29 | 0x02, 0x50, 0x43, 0x20, 0x4e, 0x45, 0x54, 0x57, 0x4f, 0x52, 0x4b, 0x20, 0x50, 0x52,
30 | 0x4f, 0x47, 0x52, 0x41, 0x4d, 0x20, 0x31, 0x2e, 0x30, 0x00, 0x02, 0x4c, 0x41, 0x4e,
31 | 0x4d, 0x41, 0x4e, 0x31, 0x2e, 0x30, 0x00, 0x02, 0x57, 0x69, 0x6e, 0x64, 0x6f, 0x77,
32 | 0x73, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x57, 0x6f, 0x72, 0x6b, 0x67, 0x72, 0x6f, 0x75,
33 | 0x70, 0x73, 0x20, 0x33, 0x2e, 0x31, 0x61, 0x00, 0x02, 0x4c, 0x4d, 0x31, 0x2e, 0x32,
34 | 0x58, 0x30, 0x30, 0x32, 0x00, 0x02, 0x4c, 0x41, 0x4e, 0x4d, 0x41, 0x4e, 0x32, 0x2e,
35 | 0x31, 0x00, 0x02, 0x4e, 0x54, 0x20, 0x4c, 0x4d, 0x20, 0x30, 0x2e, 0x31, 0x32, 0x00,
36 | 0x02, 0x53, 0x4d, 0x42, 0x20, 0x32, 0x2e, 0x30, 0x30, 0x32, 0x00 };
37 | private final int TIMEOUT = 250;
38 | private final int PORT = 445;
39 | public InetAddress host = null;
40 |
41 | // public String message = null;
42 |
43 | public void run() {
44 | Socket s = new Socket();
45 | try {
46 | s.bind(null);
47 | s.connect(new InetSocketAddress(host, PORT), TIMEOUT);
48 | OutputStream out = s.getOutputStream();
49 | for (int b : buff) {
50 | out.write(b);
51 | }
52 | out.close();
53 | s.close();
54 | } catch (IOException e) {
55 | Log.e(TAG, e.getMessage());
56 | }
57 | // setMessage(host.getHostAddress() + " sent buffer");
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Utils/Db.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network.Utils;
7 |
8 | import info.lamatricexiste.network.Network.DownloadFile;
9 |
10 | import java.io.IOException;
11 | import java.io.OutputStream;
12 | import java.nio.channels.Channels;
13 | import java.nio.channels.ReadableByteChannel;
14 | import java.nio.channels.WritableByteChannel;
15 | import java.util.zip.GZIPInputStream;
16 |
17 | import android.content.Context;
18 | import android.database.sqlite.SQLiteDatabase;
19 | import android.database.sqlite.SQLiteException;
20 | import android.util.Log;
21 |
22 | public class Db {
23 |
24 | private final static String TAG = "Db";
25 | private Context ctxt = null;
26 |
27 | // Databases information
28 | public static final String PATH = "/data/data/info.lamatricexiste.network/files/";
29 | public static final String DB_SERVICES = "services.db";
30 | public static final String DB_PROBES = "probes.db";
31 | public static final String DB_NIC = "nic.db";
32 | public static final String DB_SAVES = "saves.db";
33 |
34 | public Db(Context ctxt) {
35 | this.ctxt = ctxt;
36 | // new File(PATH).mkdirs();
37 | }
38 |
39 | public static SQLiteDatabase openDb(String db_name) {
40 | return openDb(db_name, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
41 | }
42 |
43 | public static SQLiteDatabase openDb(String db_name, int flags) {
44 | try {
45 | return SQLiteDatabase.openDatabase(PATH + db_name, null, flags);
46 | } catch (SQLiteException e) {
47 | Log.e(TAG, e.getMessage());
48 | }
49 | return null;
50 | }
51 |
52 | public void copyDbToDevice(int res, String db_name) throws NullPointerException, IOException {
53 | // InputStream in = ctxt.getResources().openRawResource(res);
54 | GZIPInputStream in = new GZIPInputStream(ctxt.getResources().openRawResource(res));
55 | OutputStream out = ctxt.openFileOutput(db_name, Context.MODE_PRIVATE);
56 | final ReadableByteChannel ic = Channels.newChannel(in);
57 | final WritableByteChannel oc = Channels.newChannel(out);
58 | DownloadFile.fastChannelCopy(ic, oc);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Utils/DbUpdate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network.Utils;
7 |
8 | import info.lamatricexiste.network.ActivityMain;
9 | import info.lamatricexiste.network.R;
10 | import info.lamatricexiste.network.Network.DownloadFile;
11 | import info.lamatricexiste.network.Network.NetInfo;
12 |
13 | import java.io.IOException;
14 | import java.lang.ref.WeakReference;
15 |
16 | import android.app.Activity;
17 | import android.app.AlertDialog;
18 | import android.app.ProgressDialog;
19 | import android.content.Context;
20 | import android.content.DialogInterface;
21 | import android.content.SharedPreferences;
22 | import android.content.DialogInterface.OnClickListener;
23 | import android.content.SharedPreferences.Editor;
24 | import android.content.pm.PackageManager.NameNotFoundException;
25 | import android.database.Cursor;
26 | import android.database.sqlite.SQLiteDatabase;
27 | import android.database.sqlite.SQLiteException;
28 | import android.os.AsyncTask;
29 | import android.preference.PreferenceManager;
30 | import android.util.Log;
31 | import android.widget.Toast;
32 |
33 | public class DbUpdate extends AsyncTask {
34 |
35 | private final static String TAG = "DbUpdate";
36 | private final static String DB_REMOTE = "http://download.lamatricexiste.info/%s.gz";
37 | private final static String REQ = "select count(%1$s) from %2$s";
38 | private int nb;
39 | private String file;
40 | private String database;
41 | private String field;
42 | private ProgressDialog progress;
43 | protected WeakReference mActivity;
44 |
45 | public DbUpdate(Activity activity, String file, String database, String field, int kilobytes) {
46 | this.file = file;
47 | this.database = database;
48 | this.field = field;
49 | mActivity = new WeakReference(activity);
50 | if (mActivity != null) {
51 | final Activity d = mActivity.get();
52 | if (d != null) {
53 | final AlertDialog.Builder dialog = new AlertDialog.Builder(d);
54 | dialog
55 | .setMessage(d.getString(R.string.preferences_resetdb_action, file,
56 | kilobytes));
57 | dialog.setPositiveButton(R.string.btn_yes, new OnClickListener() {
58 | public void onClick(DialogInterface dialog, int which) {
59 | if (!getStatus().equals(Status.RUNNING)) {
60 | execute();
61 | }
62 | }
63 | });
64 | dialog.setNegativeButton(R.string.btn_no, new OnClickListener() {
65 | public void onClick(DialogInterface dialog, int which) {
66 | cancel(true);
67 | }
68 | });
69 | dialog.show();
70 | }
71 | }
72 | }
73 |
74 | @Override
75 | protected void onPreExecute() {
76 | if (mActivity != null) {
77 | final Activity d = mActivity.get();
78 | if (d != null) {
79 | d.setProgressBarIndeterminateVisibility(true);
80 | progress = ProgressDialog.show(d, "", d.getString(R.string.task_db, file));
81 | }
82 | }
83 | }
84 |
85 | @Override
86 | protected Void doInBackground(Void... params) {
87 | try {
88 | nb = countEntries();
89 | if (mActivity != null) {
90 | final Activity d = mActivity.get();
91 | if (d != null) {
92 | remoteCopy(d);
93 | }
94 | }
95 | } catch (Exception e) {
96 | cancel(true);
97 | }
98 | return null;
99 | }
100 |
101 | private void remoteCopy(final Context ctxt) throws IOException, NullPointerException {
102 | Log.v(TAG, "Copying " + file + " remotly");
103 | if (NetInfo.isConnected(ctxt)) {
104 | new DownloadFile(ctxt, String.format(DB_REMOTE, file), ctxt.openFileOutput(file,
105 | Context.MODE_PRIVATE));
106 | }
107 | }
108 |
109 | private int countEntries() {
110 | SQLiteDatabase db = null;
111 | int nb = 0;
112 | try {
113 | db = SQLiteDatabase.openDatabase(Db.PATH + file, null,
114 | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
115 | Cursor c = db.rawQuery(String.format(REQ, field, database), null);
116 | if (c.moveToFirst()) {
117 | nb = c.getInt(0);
118 | }
119 | c.close();
120 | db.close();
121 | } catch (SQLiteException e) {
122 | if (db != null) {
123 | db.close();
124 | }
125 | return nb;
126 | }
127 | return nb;
128 | }
129 |
130 | @Override
131 | protected void onPostExecute(Void unused) {
132 | if (mActivity != null) {
133 | final Activity d = mActivity.get();
134 | if (d != null) {
135 | if (progress.isShowing()) {
136 | progress.dismiss();
137 | }
138 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(d
139 | .getApplication());
140 | d.setProgressBarIndeterminateVisibility(false);
141 | Toast.makeText(d.getApplicationContext(),
142 | d.getString(R.string.preferences_resetdb_ok, (countEntries() - nb)),
143 | Toast.LENGTH_LONG).show();
144 | try {
145 | Editor edit = prefs.edit();
146 | edit.putInt(Prefs.KEY_RESET_NICDB, d.getPackageManager().getPackageInfo(
147 | ActivityMain.PKG, 0).versionCode);
148 | edit.commit();
149 | } catch (NameNotFoundException e) {
150 | Log.e(TAG, e.getMessage());
151 | }
152 | }
153 | }
154 | }
155 |
156 | @Override
157 | protected void onCancelled() {
158 | if (progress != null && progress.isShowing()) {
159 | progress.dismiss();
160 | }
161 | if (mActivity != null) {
162 | final Activity d = mActivity.get();
163 | if (d != null) {
164 | Toast.makeText(d.getApplicationContext(), R.string.preferences_error3,
165 | Toast.LENGTH_SHORT).show();
166 | }
167 | }
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Utils/Export.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network.Utils;
7 |
8 | import info.lamatricexiste.network.Network.HostBean;
9 | import info.lamatricexiste.network.Network.NetInfo;
10 |
11 | import java.io.File;
12 | import java.io.FileWriter;
13 | import java.io.IOException;
14 | import java.text.SimpleDateFormat;
15 | import java.util.Date;
16 | import java.util.List;
17 |
18 | import android.content.Context;
19 | import android.os.Environment;
20 | import android.util.Log;
21 |
22 | public class Export {
23 |
24 | private final String TAG = "Export";
25 | private List hosts;
26 | private NetInfo net;
27 |
28 | public Export(Context ctxt, List hosts) {
29 | this.hosts = hosts;
30 | net = new NetInfo(ctxt);
31 | net.getWifiInfo();
32 | }
33 |
34 | public boolean writeToSd(String file) {
35 | String xml = prepareXml();
36 | try {
37 | FileWriter f = new FileWriter(file);
38 | f.write(xml);
39 | f.flush();
40 | f.close();
41 | return true;
42 | } catch (IOException e) {
43 | Log.e(TAG, e.getMessage());
44 | e.printStackTrace();
45 | }
46 | return false;
47 | }
48 |
49 | public boolean fileExists(String filename) {
50 | File file = new File(filename);
51 | return file.exists();
52 | }
53 |
54 | public String getFileName() {
55 | // TODO: Use getExternalFilesDir()
56 | return Environment.getExternalStorageDirectory().toString() + "/discovery-"
57 | + net.getNetIp() + ".xml";
58 | }
59 |
60 | private String prepareXml() {
61 | String xml = "\r\n" + "\r\n";
62 | // Network Information
63 | xml += "\t\r\n"
64 | + "\t\t"
65 | + (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")).format(new Date())
66 | + "\r\n" // RFC 2822
67 | + "\t\t" + net.getNetIp() + "/" + net.cidr + "\r\n"
68 | + "\t\t" + net.ssid + "\r\n" + "\t\t" + net.bssid
69 | + "\r\n" + "\t\t" + net.ip + "\r\n" + "\t\r\n";
70 |
71 | // Hosts
72 | if (hosts != null) {
73 | xml += "\t\r\n";
74 | for (int i = 0; i < hosts.size(); i++) {
75 | // Host info
76 | HostBean host = hosts.get(i);
77 | xml += "\t\t\r\n";
79 | // Open Ports //TODO: rething the XML structure to include close
80 | // and filtered ports
81 | if (host.portsOpen != null) {
82 | for (int port : host.portsOpen) {
83 | xml += "\t\t\t" + port + "/tcp open\r\n";
84 | }
85 | }
86 | xml += "\t\t\r\n";
87 | }
88 | xml += "\t\r\n";
89 | }
90 |
91 | xml += "";
92 | return xml;
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Utils/Help.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network.Utils;
7 |
8 | import info.lamatricexiste.network.R;
9 | import android.app.Activity;
10 | import android.os.Bundle;
11 |
12 | public class Help extends Activity {
13 | @Override
14 | public void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.help);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Utils/Save.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network.Utils;
7 |
8 | import info.lamatricexiste.network.Network.HostBean;
9 |
10 | import java.lang.IllegalStateException;
11 |
12 | import android.database.Cursor;
13 | import android.database.sqlite.SQLiteDatabase;
14 | import android.database.sqlite.SQLiteException;
15 | import android.util.Log;
16 |
17 | public class Save {
18 |
19 | private static final String TAG = "Save";
20 | private static final String SELECT = "select name from nic where mac=?";
21 | private static final String INSERT = "insert or replace into nic (name,mac) values (?,?)";
22 | private static final String DELETE = "delete from nic where mac=?";
23 | private static SQLiteDatabase db;
24 |
25 | public void closeDb(){
26 | if(db != null && db.isOpen()){
27 | db.close();
28 | }
29 | }
30 |
31 | public synchronized String getCustomName(HostBean host) {
32 | String name = null;
33 | Cursor c = null;
34 | try {
35 | db = getDb();
36 | c = db.rawQuery(SELECT, new String[] { host.hardwareAddress.replace(":", "").toUpperCase() });
37 | if (c.moveToFirst()) {
38 | name = c.getString(0);
39 | } else if(host.hostname != null) {
40 | name = host.hostname;
41 | }
42 | } catch (SQLiteException e) {
43 | Log.e(TAG, e.getMessage());
44 | } catch (IllegalStateException e) {
45 | Log.e(TAG, e.getMessage());
46 | } finally {
47 | if (c != null) {
48 | c.close();
49 | }
50 | }
51 | return name;
52 | }
53 |
54 | public void setCustomName(final String name, final String mac) {
55 | db = Db.openDb(Db.DB_SAVES, SQLiteDatabase.NO_LOCALIZED_COLLATORS|SQLiteDatabase.OPEN_READWRITE);
56 | try {
57 | if (db.isOpen()) {
58 | db.execSQL(INSERT, new String[] { name, mac.replace(":", "").toUpperCase() });
59 | }
60 | } catch (SQLiteException e) {
61 | Log.e(TAG, e.getMessage());
62 | } finally {
63 | closeDb();
64 | }
65 | }
66 |
67 | public boolean removeCustomName(String mac) {
68 | db = Db.openDb(Db.DB_SAVES, SQLiteDatabase.NO_LOCALIZED_COLLATORS|SQLiteDatabase.OPEN_READWRITE);
69 | try {
70 | if (db.isOpen()) {
71 | db.execSQL(DELETE, new String[] { mac.replace(":", "").toUpperCase() });
72 | return true;
73 | }
74 | return false;
75 | } catch (SQLiteException e) {
76 | Log.e(TAG, e.getMessage());
77 | return false;
78 | } finally {
79 | closeDb();
80 | }
81 | }
82 |
83 | private static synchronized SQLiteDatabase getDb(){
84 | if(db == null || !db.isOpen()) {
85 | // FIXME: read only ?
86 | db = Db.openDb(Db.DB_SAVES, SQLiteDatabase.NO_LOCALIZED_COLLATORS|SQLiteDatabase.OPEN_READONLY);
87 | }
88 | return db;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/info/lamatricexiste/network/Utils/UpdateNicDb.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
3 | * Licensed under GNU's GPL 2, see README
4 | */
5 |
6 | package info.lamatricexiste.network.Utils;
7 |
8 | import info.lamatricexiste.network.ActivityMain;
9 | import info.lamatricexiste.network.R;
10 | import info.lamatricexiste.network.Network.DownloadFile;
11 | import info.lamatricexiste.network.Network.NetInfo;
12 |
13 | import java.io.IOException;
14 | import java.lang.NullPointerException;
15 | import java.lang.ref.WeakReference;
16 |
17 | import android.app.Activity;
18 | import android.app.AlertDialog;
19 | import android.app.ProgressDialog;
20 | import android.content.Context;
21 | import android.content.DialogInterface;
22 | import android.content.SharedPreferences;
23 | import android.content.DialogInterface.OnClickListener;
24 | import android.content.SharedPreferences.Editor;
25 | import android.content.pm.PackageManager.NameNotFoundException;
26 | import android.database.Cursor;
27 | import android.database.sqlite.SQLiteDatabase;
28 | import android.database.sqlite.SQLiteException;
29 | import android.os.AsyncTask;
30 | import android.preference.PreferenceManager;
31 | import android.util.Log;
32 | import android.widget.Toast;
33 |
34 | public class UpdateNicDb extends AsyncTask {
35 |
36 | private final static String TAG = "UpdateNicDb";
37 | private final static String DB_REMOTE = "http://download.lamatricexiste.info/nic.db.gz";
38 | private final static String REQ = "select count(mac) from oui";
39 | private int nb;
40 | private ProgressDialog progress;
41 | protected WeakReference mActivity;
42 |
43 | public UpdateNicDb(Activity activity) {
44 | mActivity = new WeakReference(activity);
45 | if (mActivity != null) {
46 | final Activity d = mActivity.get();
47 | if (d != null) {
48 | final AlertDialog.Builder dialog = new AlertDialog.Builder(d);
49 | dialog.setMessage(d.getString(R.string.preferences_resetdb_action, Db.DB_NIC, 253));
50 | dialog.setPositiveButton(R.string.btn_yes, new OnClickListener() {
51 | public void onClick(DialogInterface dialog, int which) {
52 | if (!getStatus().equals(Status.RUNNING)) {
53 | execute();
54 | }
55 | }
56 | });
57 | dialog.setNegativeButton(R.string.btn_no, new OnClickListener() {
58 | public void onClick(DialogInterface dialog, int which) {
59 | cancel(true);
60 | }
61 | });
62 | dialog.show();
63 | }
64 | }
65 | }
66 |
67 | @Override
68 | protected void onPreExecute() {
69 | if (mActivity != null) {
70 | final Activity d = mActivity.get();
71 | if (d != null) {
72 | d.setProgressBarIndeterminateVisibility(true);
73 | progress = ProgressDialog.show(d, "", d.getString(R.string.task_db, Db.DB_NIC));
74 | }
75 | }
76 | }
77 |
78 | @Override
79 | protected Void doInBackground(Void... params) {
80 | try {
81 | nb = countEntries();
82 | if (mActivity != null) {
83 | final Activity d = mActivity.get();
84 | if (d != null) {
85 | remoteCopy(d);
86 | }
87 | }
88 | } catch (IOException e) {
89 | cancel(true);
90 | } catch (NullPointerException e) {
91 | cancel(true);
92 | }
93 | return null;
94 | }
95 |
96 | private void remoteCopy(final Context ctxt) throws IOException {
97 | Log.v(TAG, "Copying oui.db remotly");
98 | if (NetInfo.isConnected(ctxt)) {
99 | new DownloadFile(ctxt, DB_REMOTE, ctxt.openFileOutput(Db.DB_NIC, Context.MODE_PRIVATE));
100 | }
101 | }
102 |
103 | private int countEntries() {
104 | int nb = 0;
105 | try {
106 | SQLiteDatabase db = SQLiteDatabase.openDatabase(Db.PATH + Db.DB_NIC, null,
107 | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
108 | Cursor c = db.rawQuery(REQ, null);
109 | if (c.moveToFirst()) {
110 | nb = c.getInt(0);
111 | }
112 | c.close();
113 | db.close();
114 | } catch (SQLiteException e) {
115 | return nb;
116 | }
117 | return nb;
118 | }
119 |
120 | @Override
121 | protected void onPostExecute(Void unused) {
122 | if (mActivity != null) {
123 | final Activity d = mActivity.get();
124 | if (d != null) {
125 | if (progress.isShowing()) {
126 | progress.dismiss();
127 | }
128 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(d
129 | .getApplication());
130 | d.setProgressBarIndeterminateVisibility(false);
131 | Toast.makeText(d.getApplicationContext(),
132 | d.getString(R.string.preferences_resetdb_ok, (countEntries() - nb)),
133 | Toast.LENGTH_LONG).show();
134 | try {
135 | Editor edit = prefs.edit();
136 | edit.putInt(Prefs.KEY_RESET_NICDB, d.getPackageManager().getPackageInfo(
137 | ActivityMain.PKG, 0).versionCode);
138 | edit.commit();
139 | } catch (NameNotFoundException e) {
140 | Log.e(TAG, e.getMessage());
141 | }
142 | }
143 | }
144 | }
145 |
146 | @Override
147 | protected void onCancelled() {
148 | if (progress != null && progress.isShowing()) {
149 | progress.dismiss();
150 | }
151 | if (mActivity != null) {
152 | final Activity d = mActivity.get();
153 | if (d != null) {
154 | Toast.makeText(d.getApplicationContext(), R.string.preferences_error3,
155 | Toast.LENGTH_SHORT).show();
156 | }
157 | }
158 | }
159 | }
160 |
--------------------------------------------------------------------------------