java - Listing all devices on a network - Android -


i trying display devices fro network according tutorial: http://android-er.blogspot.ro/2015/12/lookup-manufacturer-info-by-mac-address.html no reason router ip , mac ... (weird part).. when scan fing (other android app) , after scan app results..

my code scanwifi.jar:

    package com.nliplace.nli.unealta;     import android.os.asynctask;     import android.os.bundle;     import android.support.v7.app.appcompatactivity;     import android.view.view;     import android.widget.adapterview;     import android.widget.arrayadapter;     import android.widget.button;     import android.widget.listview;     import android.widget.textview;     import android.widget.toast;      import org.json.jsonarray;     import org.json.jsonexception;     import org.json.jsonobject;      import java.io.bufferedreader;     import java.io.filenotfoundexception;     import java.io.filereader;     import java.io.ioexception;     import java.io.inputstreamreader;     import java.net.httpurlconnection;     import java.net.url;     import java.util.arraylist;      public class scanwifi extends appcompatactivity {          button btnread;         textview textresult;          listview listviewnode;         arraylist<node> listnote;         arrayadapter<node> adapter;          @override         protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_scanwifi);             btnread = (button)findviewbyid(r.id.readclient);             textresult = (textview)findviewbyid(r.id.result);              listviewnode = (listview)findviewbyid(r.id.nodelist);             listnote = new arraylist<>();             arrayadapter<node> adapter =                     new arrayadapter<node>(                             scanwifi.this,                             android.r.layout.simple_list_item_1,                             listnote);             listviewnode.setadapter(adapter);              listviewnode.setonitemclicklistener(new adapterview.onitemclicklistener() {                 @override                 public void onitemclick(adapterview<?> parent, view view, int position, long id) {                     node node = (node) parent.getadapter().getitem(position);                     toast.maketext(scanwifi.this,                             "mac:\t" + node.mac + "\n" +                                     "ip:\t" + node.ip + "\n" +                                     "company:\t" + node.company + "\n" +                                     "country:\t" + node.country + "\n" +                                     "addressl1:\t" + node.addressl1 + "\n" +                                     "addressl2:\t" + node.addressl2 + "\n" +                                     "addressl3:\t" + node.addressl3 + "\n" +                                     "type:\t" + node.type + "\n" +                                     "starthex:\t" + node.starthex + "\n" +                                     "endhex:\t" + node.endhex + "\n" +                                     "startdec:\t" + node.startdec + "\n" +                                     "enddec:\t" + node.enddec,                             toast.length_short).show();                 }             });              btnread.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                     new taskreadaddresses(listnote, listviewnode).execute();                 }             });         }            class node {             string ip;             string mac;              string jsonbody;             string starthex;             string endhex;             string startdec;             string enddec;             string company;             string addressl1;             string addressl2;             string addressl3;             string country;             string type;              string remark;              string querystring = "http://www.macvendorlookup.com/api/v2/";              node(string ip, string mac){                 this.ip = ip;                 this.mac = mac;                 querymacvendorlookup();             }              @override             public string tostring() {                 return "ip: " + ip + "\n" + "mac: " + mac + "\n" + company + "\n" + remark;             }              private string sendquery(string qmac) throws ioexception{                 string result = "";                  url searchurl = new url(querystring + qmac);                  httpurlconnection httpurlconnection = (httpurlconnection) searchurl.openconnection();                  if(httpurlconnection.getresponsecode() == httpurlconnection.http_ok){                     inputstreamreader inputstreamreader = new inputstreamreader(httpurlconnection.getinputstream());                     bufferedreader bufferedreader = new bufferedreader(                             inputstreamreader,                             8192);                      string line = null;                     while((line = bufferedreader.readline()) != null){                         result += line;                     }                      bufferedreader.close();                 }                  return result;             }               private void parseresult(string json){                  try {                     jsonarray jsonarray = new jsonarray(json);                     jsonobject jsonobject = (jsonobject) jsonarray.get(0);                     starthex = jsonobject.getstring("starthex");                     endhex = jsonobject.getstring("endhex");                     startdec = jsonobject.getstring("startdec");                     enddec = jsonobject.getstring("enddec");                     company = jsonobject.getstring("company");                     addressl1 = jsonobject.getstring("addressl1");                     addressl2 = jsonobject.getstring("addressl2");                     addressl3 = jsonobject.getstring("addressl3");                     country = jsonobject.getstring("country");                     type = jsonobject.getstring("type");                     remark = "ok";                  } catch (jsonexception e) {                     e.printstacktrace();                     remark = e.getmessage();                 }              }              private void querymacvendorlookup(){                 try {                     jsonbody = sendquery(mac);                     parseresult(jsonbody);                 } catch (ioexception e) {                     e.printstacktrace();                 }             }         }          private class taskreadaddresses extends asynctask<void, node, void> {              arraylist<node> array;             listview listview;              taskreadaddresses(arraylist<node> array, listview v){                 listview = v;                 this.array = array;                 array.clear();                 textresult.settext("querying...");             }              @override             protected void doinbackground(void... params) {                 readaddresses();                  return null;             }              @override             protected void onpostexecute(void avoid) {                 textresult.settext("done");             }              @override             protected void onprogressupdate(node... values) {                 listnote.add(values[0]);                 ((arrayadapter)(listview.getadapter())).notifydatasetchanged();              }              private void readaddresses() {                  bufferedreader bufferedreader = null;                  try {                     bufferedreader = new bufferedreader(new filereader("/proc/net/arp"));                      string line;                     while ((line = bufferedreader.readline()) != null) {                         string[] splitted = line.split(" +");                         if (splitted != null && splitted.length >= 4) {                             string ip = splitted[0];                             string mac = splitted[3];                             if (mac.matches("..:..:..:..:..:..")) {                                 node thisnode = new node(ip, mac);                                 publishprogress(thisnode);                             }                         }                     }                  } catch (filenotfoundexception e) {                     e.printstacktrace();                 } catch (ioexception e) {                     e.printstacktrace();                 } finally{                     try {                         bufferedreader.close();                     } catch (ioexception e) {                         e.printstacktrace();                     }                 }             }     } } 

my code activity_scanwifi.xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:padding="16dp"     android:orientation="vertical"     tools:context="com.nliplace.nli.unealta.scanwifi">      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textappearance="?android:attr/textappearancelarge"         android:text="aceasta activitate foloseste un api pentru identifica dispozitive cunoscute."         android:id="@+id/textview11" />      <button         android:id="@+id/readclient"         android:layout_width="156dp"         android:layout_height="wrap_content"         android:textallcaps="false"         android:text="scaneaza"         android:layout_gravity="center_horizontal" />      <textview         android:id="@+id/result"         android:layout_width="match_parent"         android:layout_height="wrap_content"/>      <listview         android:id="@+id/nodelist"         android:layout_width="match_parent"         android:layout_height="wrap_content"/> </linearlayout> 

to append in file /proc/net/arp need make ping on network.

option 1: ping -b 192.168.0.255

problem: don't windows divices becouse deny broadcast ping.

option 2: (recommended)

ping for's.

problem: append fille pinged ip , no mac (00:00:00:00:00:00) , have deny inalid mac's.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -