Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting device network urls calls

I'm trying to build an application that gives the user statistics about his network usage,

From 3G/Wifi surfing to application network usage.

The main important data I'm looking for, are the urls of the network calls.

I have next code, to find the browser history:

private void getBrowserHistory()
{
    String[] proj = new String[]{Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL};
    String sel = Browser.BookmarkColumns.BOOKMARK + " = 0"; // 0 = history, 1 = bookmark
    Cursor mCur = this.managedQuery(Browser.BOOKMARKS_URI, proj, sel, null, null);
    this.startManagingCursor(mCur);
    mCur.moveToFirst();

    if (mCur.moveToFirst() && mCur.getCount() > 0)
    {
        while (mCur.isAfterLast() == false)
        {
            String title = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.TITLE));
            String url = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.URL));
            Log.d(LOG_TAG, "Site title: " + title);
            Log.d(LOG_TAG, "Site url: " + url);
            mCur.moveToNext();
        }
    }
}

But to find the applications network usage I need something more like WireShark

I assume final solution for that issue is complicated, but any advice would be welcome.

like image 329
David Avatar asked Oct 02 '22 08:10

David


1 Answers

If, like you said, you are dealing with a rooted device, you can set your monitoring application as the default system proxy.

This way, by acting as a transparent proxy, you will be able to detect the ingoing and outgoing connections.

Where do I start?

If you want to take a look at a possible implementation, you can try with ProxyDroid, which is open-source and definitely a good starting point.

What you should do

What you need to do is trigger some iptables commands in order to set your application as the system proxy: here you can see how ProxyDroid does that.

Your application will then listen for connection requests, execute them and send the responses accordingly: again, this is a very basic example of how the whole thing works at your application's side.

like image 103
Sebastiano Avatar answered Oct 05 '22 12:10

Sebastiano