VisualBuilder
  Home > Java > Tutorials > Changes in NetworkInterface Class - Java 1.6 Tutorial
Tell a friend
Link to us
Total Members
      Members: 84772
     
Sitemap Forum Chat
Home
Java 1.6 Tutorial Home
1 . Collections Enhancements
2 . Console Class
3 . ArrayDeque Class
4 . ConcurrentSkipListMap Class
5 . ConcurrentSkipListSet Class
6 . HashSet Collection Framework
7 . Java.util
8 . File and Directory Permissions in JDK1.6
9 . Core Java Internationalization
10 . Enhanced memory leak analysis and detection
11 . Changes in NetworkInterface Class
12 . API Changes
13 .  Compression Using Java 6
14 . ZipOutputStream Class To Compress Files in Zip Format
15 . ZipInputStream Class To Decompress Zip files
16 . Enhancements for Web Services
17 . Steps to use the Scripting API
18 . Java Scripting API Introduction
 
 
Java Home
Java Members (27650)
Java Member Articles ( 40 )
Java Discussion (275)
Java Q & A ( 174 )
- Java Ask Question
- Java Questions
- Java Unanswered Questions
Java Resources
Java Source Code (1096)
Java Articles (551)
Java Blogs (118)
Java Jobs (797)
Java Components (85)
Java Books (169)
Java Websites (127)
Java News (103)
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.Net Security,Internationalisation And Deployment
ASP.NET Tutorial
C# Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (451 )
Source Code (3275 )
Articles (359 )
Books (372 )
Components (1596 )
News (892 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise

Java java6 Tutorial
 Changes in NetworkInterface Class
  << Prev: Enhanced memory leak analysis and detection Next: API Changes >>





This class is used to represent a Network Interface and it is made up of a name and a IP addresses list assigned to this interface. In Java 6, this class provides some new methods for accessing state and configuration information and this information is related to system's network adapters. This includes information like broadcast address, list object with all or a subset of the InterfaceAddress,subnet mask, hardware address (MAC addresses) and MTU size.



Some new methods are added in NetworkInterface class are as follows:

public boolean isUp()

This method returns true if the network interface is up and running. Up specifies that routing entries have been set up for the network interface. And running specifies that required system resources have been allocated.



public boolean isLoopback()

This method returns true if the network interface is a loopback interface.



public boolean isPointToPoint()

This method returns true if the network interface is point to point interface.



public boolean supportsMulticast()

This method is used to know the network interface is support multicasting or not. If yes then its return true.



public byte[] getHardwareAddress()

This method is used to get the byte array of MAC address. It return null if the address is not accessible or doesn't exist.



public int getMTU()

This method returns the value of MTU (Maximum Transmission Unit) of this interface.

Above all methods throws an SocketException if an I/O error occurs.



Example:










import java.util.*;

import java.net.*;

public class NetInt

{

   public static void main(String args[])throws SocketException

   {

      Enumeration netis= NetworkInterface.getNetworkInterfaces();

      while(netis.hasMoreElements())

      {

             NetworkInterface nis=(NetworkInterface)netis.nextElement();

            System.out.println("Network Interface name is :"+nis.getName());

           System.out.println("Display name of network interface is :" +nis.getDisplayName());

           System.out.println("Network Interface is up and running :" +nis.isUp());

           System.out.println("Network Interface is loopback :" +nis.isLoopback());

           System.out.println("Network Interface is point to point interface :"+nis.isPointToPoint());

           System.out.println("Network Interface support multicasting :" +nis.supportsMulticast());

           System.out.println("Network Interface MTU value is :" +nis.getMTU());

           System.out.println("Network Interface is virtual interface :" +nis.isVirtual());

           System.out.println("Network Interface has any Paren :" +nis.getParent());

           byte[] haddress=nis.getHardwareAddress();

           if (haddress!= null)

             {

              System.out.print (" Hardware address = ");

              for (int i = 0; i < haddress.length; i++)

                  System.out.printf ("%02X%c", haddress [i],(i != haddress.length-1) ? '-' :'\0');

              System.out.println();

              }

           List iaddress=nis.getInterfaceAddresses();

           Iterator iiaddress=iaddress.iterator();

           while(iiaddress.hasNext())

          {

             InterfaceAddress iadd=(InterfaceAddress)iiaddress.next();

             System.out.println("Interface Address -");

             System.out.println("InetAddress of the Interface Address :" +iadd.getAddress());

             System.out.println("Broadcast Addres of the Interface Address :"+iadd.getBroadcast());

             System.out.println("Network Prefix Length of the Interface Address :"+iadd.getNetworkPrefixLength());

          }

          System.out.println();

          }

     }

}


Output:- The following is the sample output for the above program.


Network Interface name is :lo

Display name of network interface is :MS TCP Loopback interface

Network Interface is up and running :true

Network Interface is loopback :true

Network Interface is point to point interface :false

Network Interface support multicasting :true

Network Interface MTU value is :1520

Network Interface is virtual interface :false

Network Interface has any Paren :null

Interface Address -

InetAddress of the Interface Address :/127.0.0.1

Broadcast Addres of the Interface Address :/127.255.255.255

Network Prefix Length of the Interface Address :8


Network Interface name is :eth0

Display name of network interface is :Intel(R) PRO/Wireless 2200BG Network Connection - Packet Scheduler Miniport

Network Interface is up and running :false

Network Interface is loopback :false

Network Interface is point to point interface :false

Network Interface support multicasting :true

Network Interface MTU value is :1500

Network Interface is virtual interface :false

Network Interface has any Paren :null

Hardware address = 00-13-CE-A8-56-0D










  << Prev: Enhanced memory leak analysis and detection Next: API Changes >>
Java Java6 Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
internet fax
Montignac Shop
 
 
ADVERTISEMENT
Partner List
Code Project
ASP Alliance
More
 
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising