ANDROID PROGRAMMING : DISPLAYING NETWORK INTERFACE CARD INFORMATION ON ANDROID DEVICES
Welcome to . This post is still about android programming is that we will create a simple android application that can be usedshows information from the Network Interface Card (NIC)which is connected to our android device.
Here I useEclipse Software, if you use Android Studio, it's the same with the source code, you just have to choose which one is more familiar to you. Tutorial on making an android application that is able to displayNIC (Network Interface Card)on your android device using the latest eclipse software.
The following android programming tutorial shows the Network Interface Card, here we use 2Class Network InterfaceandClass InetAddress(clarification below):
1. Create a new project with the nameMy IP_Helmy, use minimalAPI 11 GingerBeardthen selectNextuntil the finish
Create New Project |
2. ModificationAndroidManifest.xmland add permissionsInternet usersuseful so that the application can later access the internet
Add Internet Permission |
Create Interface |
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:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.MyIP.ipsaya_helmy.MainActivity" >
Code version display |
Graphic Display |
5. Write the code to work on the application on theMyIP_helmy - src - com.blabla - MainActivity.java
Open Mainjava |
6. Enter the source code below onMainActivity.java package com.
MyIP.ipsaya_helmy;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import org.apache.http.conn.util.InetAddressUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
);
public listgetLocalIpv4Address()
Strings nicName, nicIpAddr, nicMacAddr="";
ListlistInterface = new ArrayList ();
try
//find out the list of NICs in the Android device
for(EnumerationnicEnum =
NetworkInterface.getNetworkInterfaces();
nicEnum.hasMoreElements();)
NetworkInterface nic = nicEnum.nextElement();
// find out, the IP address contained in each NIC
for(EnumerationipEnum =
nic.getInetAddresses();
ipEnum.hasMoreElements();)
InetAddress ip = (InetAddress)ipEnum.nextElement();
//check if the NIC has an IPv4 address
if(InetAddressUtils.isIPv4Address(ip.getHostAddress()))
//get NIC name
nicName = nic.getDisplayName();
//get MAC addr NIC
byte mac = nic.getHardwareAddress();
if(mac!=null)
for(int i=0;inicMacAddr +=
String.format("%02X%s",
maci,(i//get IP address on NIC
nicIpAddr = ip.getHostAddress();
//add to list
listInterface.add(nicName+" ; "+nicMacAddr+" "+nicIpAddr);
return listInterface;
catch(SocketException se)
Log.e("getLocalIpv4Address", se.toString());
return null;
Enter Code |
A brief description :
- Class Network Interfaceused to represent network interfaces (LAN Card, Wireless LAN Card, modem etc.) contained in a device. A NIC is defined by its MAC address and device name which is platform independent. The NetworkInterface class provides a method for receiving all available info on the NIC listed in the procedure
- Class InetAddressused to receive information about the V4 or V6 IP Address contained on a NIC and to recognize the host name of the device registered on the NIC.
a Domain Name Server
a Domain Name Server
The result is as follows, please run on your SmartPhone:
1. Right clickproject run as- chooseandroid deviceyou and run
Select android device |
2. The results are as follows :
That's the android tutorial aboutHow to Make an Applicationwhich can display NIC and IP information on modern android applications so that it is useful if you have difficulties you can download the project above via the link below.
Download IPNIC_My Android