Lookup Manufacturer Information Past Times Mac Address, Using Www.Macvendorlookup.Com Api

Posted on

Last post service exhibit how to “Retrieve IP too MAC addresses of Android WiFi tethering clients from /proc/net/arp“. This instance exhibit how to larn vendor/manufacturer information of the associated MAC addresses.

(You tin flame download runnable APK from link on bottom)

http://www.macvendorlookup.com/api furnish API to lookup MAC Address Vendor/Manufacturer info.

Notice that this instance haven’t grip mistake condition.


MainActivity.java

package com.blogspot.android_er.androidlistclient;  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;  world course of education MainActivity 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_main);         btnRead = (Button)findViewById(R.id.readclient);         textResult = (TextView)findViewById(R.id.result);          listViewNode = (ListView)findViewById(R.id.nodelist);         listNote = novel ArrayList<>();         ArrayAdapter<Node> adapter =                 novel ArrayAdapter<Node>(                         MainActivity.this,                         android.R.layout.simple_list_item_1,                         listNote);         listViewNode.setAdapter(adapter);          listViewNode.setOnItemClickListener(new AdapterView.OnItemClickListener() {             @Override             world void onItemClick(AdapterView<?> parent, View view, int position, long id) {                 Node node = (Node) parent.getAdapter().getItem(position);                 Toast.makeText(MainActivity.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             world void onClick(View v) {                 novel TaskReadAddresses(listNote, listViewNode).execute();             }         });     }        course of education 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         world String toString() {             render "IP: " + ip + "\n" + "MAC: " + mac + "\n" + companionship + "\n" + remark;         }          somebody String sendQuery(String qMac) throws IOException{             String outcome = "";              URL searchURL = novel URL(queryString + qMac);              HttpURLConnection httpURLConnection = (HttpURLConnection) searchURL.openConnection();              if(httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK){                 InputStreamReader inputStreamReader = novel InputStreamReader(httpURLConnection.getInputStream());                 BufferedReader bufferedReader = novel BufferedReader(                         inputStreamReader,                         8192);                  String business = null;                 while((line = bufferedReader.readLine()) != null){                     outcome += line;                 }                  bufferedReader.close();             }              render result;         }           somebody void ParseResult(String json){              endeavour {                 JSONArray jsonArray = novel JSONArray(json);                 JSONObject jsonObject = (JSONObject) jsonArray.get(0);                 startHex = jsonObject.getString("startHex");                 endHex = jsonObject.getString("endHex");                 startDec = jsonObject.getString("startDec");                 endDec = jsonObject.getString("endDec");                 companionship = jsonObject.getString("company");                 addressL1 = jsonObject.getString("addressL1");                 addressL2 = jsonObject.getString("addressL2");                 addressL3 = jsonObject.getString("addressL3");                 province = jsonObject.getString("country");                 type = jsonObject.getString("type");                 remark = "OK";              } grab (JSONException e) {                 e.printStackTrace();                 remark = e.getMessage();             }          }          somebody void queryMacVendorLookup(){             endeavour {                 jsonBody = sendQuery(mac);                 ParseResult(jsonBody);             } grab (IOException e) {                 e.printStackTrace();             }         }     }      somebody course of education 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();              render null;         }          @Override         protected void onPostExecute(Void aVoid) {             textResult.setText("Done");         }          @Override         protected void onProgressUpdate(Node... values) {             listNote.add(values[0]);             ((ArrayAdapter)(listView.getAdapter())).notifyDataSetChanged();          }          somebody void readAddresses() {              BufferedReader bufferedReader = null;              endeavour {                 bufferedReader = novel BufferedReader(new FileReader("/proc/net/arp"));                  String line;                 spell ((line = bufferedReader.readLine()) != null) {                     String[] splitted = line.split(" +");                     if (splitted != cipher && splitted.length >= 4) {                         String ip = splitted[0];                         String mac = splitted[3];                         if (mac.matches("..:..:..:..:..:..")) {                             Node thisNode = novel Node(ip, mac);                             publishProgress(thisNode);                         }                     }                 }              } grab (FileNotFoundException e) {                 e.printStackTrace();             } grab (IOException e) {                 e.printStackTrace();             } finally{                 endeavour {                     bufferedReader.close();                 } grab (IOException e) {                     e.printStackTrace();                 }             }         }     } }  

layout/activity_main.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.blogspot.android_er.androidlistclient.MainActivity">      <TextView         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center_horizontal"         android:autoLink="web"         android:text="https://rootandroid.org//"         android:textStyle="bold" />      <Button         android:id="@+id/readclient"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textAllCaps="false"         android:text="Read Ip/MAC addresses"/>      <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>  

uses-permission of “android.permission.INTERNET” is needed inwards AndroidManifest.xml

Retrieve IP too MAC addresses of Android WiFi tethering clients Lookup manufacturer information past times MAC address, using www.macvendorlookup.com APIDownload runnable APK .

Next:
– Get HostName of WiFi hotspot clients, too banking concern check if it is withal connected.