Advertisement here

Showing Nic In Android Programming

ANDROID PROGRAMMING : DISPLAYING NETWORK INTERFACE CARD INFORMATION ON ANDROID DEVICES

 MENAMPILKAN INFORMASI NETWORK INTERFACE CARD PADA PERANGKAT ANDROID Menampilkan NIC pada Pemrograman Android

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

 MENAMPILKAN INFORMASI NETWORK INTERFACE CARD PADA PERANGKAT ANDROID Menampilkan NIC pada Pemrograman Android
Create New Project
2. ModificationAndroidManifest.xmland add permissionsInternet usersuseful so that the application can later access the internet
 MENAMPILKAN INFORMASI NETWORK INTERFACE CARD PADA PERANGKAT ANDROID Menampilkan NIC pada Pemrograman Android
Add Internet Permission
3. Create a display user interface with a filenamemain_activity.xml

 MENAMPILKAN INFORMASI NETWORK INTERFACE CARD PADA PERANGKAT ANDROID Menampilkan NIC pada Pemrograman Android
Create Interface
4. Type the following source code on theres - layout - main_activity.xml

 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" >

   
android:id="@+id/button1"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:text="View My IP" />


 MENAMPILKAN INFORMASI NETWORK INTERFACE CARD PADA PERANGKAT ANDROID Menampilkan NIC pada Pemrograman Android
Code version display
 MENAMPILKAN INFORMASI NETWORK INTERFACE CARD PADA PERANGKAT ANDROID Menampilkan NIC pada Pemrograman Android
Graphic Display
5. Write the code to work on the application on theMyIP_helmy - src - com.blabla - MainActivity.java

 MENAMPILKAN INFORMASI NETWORK INTERFACE CARD PADA PERANGKAT ANDROID Menampilkan NIC pada Pemrograman Android
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;
   
   

 MENAMPILKAN INFORMASI NETWORK INTERFACE CARD PADA PERANGKAT ANDROID Menampilkan NIC pada Pemrograman Android
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

The result is as follows, please run on your SmartPhone:

1. Right clickproject run as- chooseandroid deviceyou and run

 MENAMPILKAN INFORMASI NETWORK INTERFACE CARD PADA PERANGKAT ANDROID Menampilkan NIC pada Pemrograman Android
Select android device

2. The results are as follows :

 MENAMPILKAN INFORMASI NETWORK INTERFACE CARD PADA PERANGKAT ANDROID Menampilkan NIC pada Pemrograman Android
Results

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
Next Post Previous Post
No Comment
Add Comment
comment url
Android