Android Open Source - android_network_discovery Dns Discovery






From Project

Back to project page android_network_discovery.

License

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.

Java Source Code

/*
 * Copyright (C) 2009-2010 Aubort Jean-Baptiste (Rorist)
 * Licensed under GNU's GPL 2, see README
 *///from  www .ja v a 2s . c  om

package info.lamatricexiste.network;

import info.lamatricexiste.network.Network.HardwareAddress;
import info.lamatricexiste.network.Network.HostBean;
import info.lamatricexiste.network.Network.NetInfo;
import info.lamatricexiste.network.Utils.Prefs;

import java.io.IOException;
import java.net.InetAddress;

import android.database.sqlite.SQLiteDatabaseCorruptException;
import android.util.Log;

public class DnsDiscovery extends AbstractDiscovery {

    private final String TAG = "DnsDiscovery";

    public DnsDiscovery(ActivityDiscovery discover) {
        super(discover);
    }

    @Override
    protected Void doInBackground(Void... params) {
        if (mDiscover != null) {
            final ActivityDiscovery discover = mDiscover.get();
            if (discover != null) {
                Log.i(TAG, "start=" + NetInfo.getIpFromLongUnsigned(start) + " (" + start
                        + "), end=" + NetInfo.getIpFromLongUnsigned(end) + " (" + end
                        + "), length=" + size);

                int timeout = Integer.parseInt(discover.prefs.getString(Prefs.KEY_TIMEOUT_DISCOVER,
                        Prefs.DEFAULT_TIMEOUT_DISCOVER));
                Log.i(TAG, "timeout=" + timeout + "ms");

                for (long i = start; i < end + 1; i++) {
                    hosts_done++;
                    HostBean host = new HostBean();
                    host.ipAddress = NetInfo.getIpFromLongUnsigned(i);
                    try {
                        InetAddress ia = InetAddress.getByName(host.ipAddress);
                        host.hostname = ia.getCanonicalHostName();
                        host.isAlive = ia.isReachable(timeout) ? 1 : 0;
                    } catch (java.net.UnknownHostException e) {
                        Log.e(TAG, e.getMessage());
                    } catch (IOException e) {
                        Log.e(TAG, e.getMessage());
                    }
                    if (host.hostname != null && !host.hostname.equals(host.ipAddress)) {
                        // Is gateway ?
                        if (discover.net.gatewayIp.equals(host.ipAddress)) {
                            host.deviceType = 1;
                        }
                        // Mac Addr
                        host.hardwareAddress = HardwareAddress.getHardwareAddress(host.ipAddress);
                        // NIC vendor
                        try {
                            host.nicVendor = HardwareAddress.getNicVendor(host.hardwareAddress);
                        } catch (SQLiteDatabaseCorruptException e) {
                            Log.e(TAG, e.getMessage());
                        }
                        publishProgress(host);
                    } else {
                        publishProgress((HostBean) null);
                    }
                }
            }
        }
        return null;
    }

}




Java Source Code List

info.lamatricexiste.network.AbstractDiscovery.java
info.lamatricexiste.network.ActivityDiscovery.java
info.lamatricexiste.network.ActivityMain.java
info.lamatricexiste.network.ActivityNet.java
info.lamatricexiste.network.ActivityPortscan.java
info.lamatricexiste.network.AsyncPortscan.java
info.lamatricexiste.network.DatabaseHelper.java
info.lamatricexiste.network.DefaultDiscovery.java
info.lamatricexiste.network.DiscoverActivity.java
info.lamatricexiste.network.DnsDiscovery.java
info.lamatricexiste.network.NetworkChange.java
info.lamatricexiste.network.Network.Banner.java
info.lamatricexiste.network.Network.DownloadFile.java
info.lamatricexiste.network.Network.HardwareAddress.java
info.lamatricexiste.network.Network.HostBean.java
info.lamatricexiste.network.Network.NetInfo.java
info.lamatricexiste.network.Network.OsFingerprint.java
info.lamatricexiste.network.Network.Ping.java
info.lamatricexiste.network.Network.RateControl.java
info.lamatricexiste.network.Network.SendSmbNegotiate.java
info.lamatricexiste.network.Utils.DbUpdate.java
info.lamatricexiste.network.Utils.Db.java
info.lamatricexiste.network.Utils.Export.java
info.lamatricexiste.network.Utils.Help.java
info.lamatricexiste.network.Utils.Prefs.java
info.lamatricexiste.network.Utils.Save.java
info.lamatricexiste.network.Utils.UpdateNicDb.java
info.lamatricexiste.network.connectivity.java
info.lamatricexiste.network.portscan.java
info.lamatricexiste.network.wifiinfo.java