Back to project page android_network_discovery.
The source code is released under:
GNU General Public License
If you think the Android project android_network_discovery listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package info.lamatricexiste.network; /*ww w . j a va 2s .co m*/ import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.os.Environment; import android.util.Log; public class DatabaseHelper extends SQLiteOpenHelper { // Database Version private static final int DATABASE_VERSION = 3; // Database Name private static final String DATABASE_NAME = Environment .getExternalStorageDirectory().toString() + "/databases/connectivity.db"; // Table Names private static final String wifi = "WiFiInfo"; private static final String conn = "ConnectivityManager"; private static final String pscan = "PortScan"; // Column Names in WiFiInfo Table private static final String ctime = "Time"; private static final String wlat = "Latitude"; private static final String wlng = "Longitude"; private static final String ssid = "SSID"; private static final String bssid = "BSSID"; private static final String ip_add = "IPAddress"; private static final String rssi = "RSSI"; private static final String lspeed = "LinkSpeed"; private static final String uuid = "UUID"; // Column Names in ConnectivityManager Table private static final String cmtime = "Time"; private static final String cmntype = "Network"; private static final String cmlat = "Latitude"; private static final String cmlng = "Longitude"; private static final String cmprov = "Provider"; private static final String cmalti = "Altitude"; private static final String cmaccu = "Accuracy"; private static final String cmspeed = "Speed"; private static final String cmbear = "Bearing"; // Column Names in PortScan Table private static final String scan_UUID = "UUID"; private static final String mac_add = "MAC"; private static final String ip_addr = "IP"; private static final String ports = "Ports"; private static final String pstime = "Time"; SQLiteDatabase database; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } public void onCreate(SQLiteDatabase db) { String create_wifitable = "CREATE TABLE " + wifi + " ( " + ctime + " TEXT PRIMARY KEY, " + uuid + " TEXT, " + wlat + " TEXT, " + wlng + " TEXT, " + ssid + " TEXT, " + bssid + " TEXT, " + ip_add + " TEXT, " + rssi + " TEXT, " + lspeed + " TEXT " + " );"; String create_conntable = "CREATE TABLE " + conn + " ( " + cmtime + " TEXT PRIMARY KEY, " + cmntype + " TEXT, " + cmlat + " TEXT, " + cmlng + " TEXT, " + cmprov + " TEXT, " + cmalti + " TEXT, " + cmaccu + " TEXT, " + cmspeed + " TEXT, " + cmbear + " TEXT" + " );"; String create_portscan = "CREATE TABLE " + pscan + " ( " + pstime + " TEXT PRIMARY KEY, " + scan_UUID + " TEXT, " + mac_add + " TEXT, " + ip_addr + " TEXT, " + ports + " TEXT " + " ); "; Log.i("Command", create_portscan); db.execSQL(create_wifitable); db.execSQL(create_conntable); db.execSQL(create_portscan); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // on upgrade drop older tables db.execSQL("DROP TABLE IF EXISTS " + wifi); db.execSQL("DROP TABLE IF EXISTS " + conn); db.execSQL("DROP TABLE IF EXISTS " + pscan); // create new tables onCreate(db); } public long createWifi(wifiinfo wi) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(uuid, wi.scan_UUID); values.put(ctime, wi.now.toString()); values.put(wlat, wi.lat); values.put(wlng, wi.lng); values.put(bssid, wi.bssid); values.put(rssi, wi.rssi); values.put(ssid, wi.ssid); values.put(ip_add, wi.IP_Address); values.put(lspeed, wi.link_speed); // Inserting Row long wifi_id = db.insert(wifi, null, values); // Closing database connection db.close(); return wifi_id; } public long createConnectiviy(connectivity co) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(cmtime, co.now.toString()); values.put(cmntype, co.network_type); values.put(cmlat, co.lat); values.put(cmlng, co.lng); values.put(cmaccu, co.accuracy); values.put(cmalti, co.altitude); values.put(cmbear, co.bearing); values.put(cmprov, co.provider); values.put(cmspeed, co.speed); long conn_id = db.insert(conn, null, values); db.close(); return conn_id; } public long createPortScan(portscan ps) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(pstime, ps.now.toString()); values.put(mac_add, ps.mac_address); values.put(ip_addr, ps.ip_Address); values.put(ports, ps.ports); values.put(scan_UUID, ps.scan_UUID); Log.i("Vlaues of PS", ""+values); long ps_id = db.insert(pscan, null, values); Log.i("Created PortScan",""+ps_id); db.close(); return ps_id; } }