Package java.net

Examples of java.net.NetworkInterface


public class NetworkHelper {

  public static void main(String[] args) throws SocketException {
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    while(interfaces.hasMoreElements()) {
      NetworkInterface i = interfaces.nextElement();
      if(i.isVirtual()) {
        continue;
      }
      if(i.isLoopback()) {
        continue;
      }
      if(i.isPointToPoint()) {
        continue;
      }
      byte[] macAddress = i.getHardwareAddress();
      if(macAddress == null) {
        continue;
      }
      if(i.getInetAddresses().hasMoreElements()==false) {
        continue;
      }

     
      System.out.println(i.getDisplayName());
      System.out.println( " Name:"+i.getName() );
      System.out.println( " MAC Address:"+StringHelper.asHex(macAddress) );
      Enumeration<InetAddress> inetAddresses = i.getInetAddresses();
      while(inetAddresses.hasMoreElements()) {
        InetAddress inetAddress = inetAddresses.nextElement();
        System.out.println(" Internet Address:"+StringHelper.asHex(inetAddress.getAddress())+"<"+inetAddress.getHostName()+">");
      }
      System.out.println( "  Is Loop back:"+i.isLoopback() );
      System.out.println( "  Can Multicast:"+i.supportsMulticast() );
      System.out.println("");
    }
  }
View Full Code Here


    // Test - all addresses bound network interface is local address
    Enumeration<NetworkInterface> interfaces = NetworkInterface
        .getNetworkInterfaces();
    if (interfaces != null) { // Iterate through all network interfaces
      while (interfaces.hasMoreElements()) {
        NetworkInterface i = interfaces.nextElement();
        Enumeration<InetAddress> addrs = i.getInetAddresses();
        if (addrs == null) {
          continue;
        }
        // Iterate through all the addresses of a network interface
        while (addrs.hasMoreElements()) {
View Full Code Here

      String superUserShortName) throws IOException {
    ArrayList<String> ipList = new ArrayList<String>();
    Enumeration<NetworkInterface> netInterfaceList = NetworkInterface
        .getNetworkInterfaces();
    while (netInterfaceList.hasMoreElements()) {
      NetworkInterface inf = netInterfaceList.nextElement();
      Enumeration<InetAddress> addrList = inf.getInetAddresses();
      while (addrList.hasMoreElements()) {
        InetAddress addr = addrList.nextElement();
        ipList.add(addr.getHostAddress());
      }
    }
View Full Code Here

  public static Fun rli_get_inets() {
    Vector V=new Vector();
    try {
      Enumeration E=NetworkInterface.getNetworkInterfaces();
      while(E.hasMoreElements()) {
        NetworkInterface I=(NetworkInterface)E.nextElement();
        Enumeration A=I.getInetAddresses();
        while(A.hasMoreElements()) {
          InetAddress IA=(InetAddress)A.nextElement();
          if(IA.isSiteLocalAddress()) {// || IA.isLoopbackAddress()) {
            String adr=IA.getHostAddress();
            // String adr=IA.getCanonicalHostName();
View Full Code Here

     
      InetAddress localAddress = null;
     
      outer: while (networkInterfaces.hasMoreElements())
      {
         NetworkInterface networkInterface = networkInterfaces.nextElement();
         if (networkInterface.isLoopback() || networkInterface.isVirtual() || !networkInterface.isUp() ||
                  !networkInterface.supportsMulticast())
         {
            continue;
         }
        
         Enumeration<InetAddress> en = networkInterface.getInetAddresses();
        
         while (en.hasMoreElements())
         {
            InetAddress ia = en.nextElement();
           
View Full Code Here

        try {
            ArrayList<String> list = new ArrayList<String>();
            Enumeration<NetworkInterface> e = NetworkInterface
                    .getNetworkInterfaces();
            while (e.hasMoreElements()) {
                NetworkInterface ni = e.nextElement();
                byte[] mac = ni.getHardwareAddress();
                if (mac != null) {
                    String x = StringUtils.convertBytesToHex(mac);
                    list.add(x);
                }
            }
View Full Code Here

        }
        try {
            InetAddress dest = InetAddress.getByName(hostname);
            Enumeration en = NetworkInterface.getNetworkInterfaces();
            while (en.hasMoreElements()) {
                NetworkInterface iface = (NetworkInterface) en.nextElement();
                Enumeration ine = iface.getInetAddresses();
                while (ine.hasMoreElements()) {
                    InetAddress address = (InetAddress) ine.nextElement();
                    if (address.equals(dest)) {
                        isSameMachine = true;
                    }
View Full Code Here

        }
        try {
            InetAddress dest = InetAddress.getByName(hostname);
            Enumeration en = NetworkInterface.getNetworkInterfaces();
            while(en.hasMoreElements()) {
                NetworkInterface iface = (NetworkInterface) en.nextElement();
                Enumeration ine = iface.getInetAddresses();
                while (ine.hasMoreElements()) {
                    InetAddress address = (InetAddress) ine.nextElement();
                    if(address.equals(dest)) {
                        isSameMachine = true;
                    }
View Full Code Here

   *
   */
  public static String[] getIPs(String strInterface)
    throws UnknownHostException {
    try {
      NetworkInterface netIF = NetworkInterface.getByName(strInterface);
      if (netIF == null)
        return new String[] { InetAddress.getLocalHost()
                              .getHostAddress() };
      else {
        Vector<String> ips = new Vector<String>();
        Enumeration e = netIF.getInetAddresses();
        while (e.hasMoreElements())
          ips.add(((InetAddress) e.nextElement()).getHostAddress());
        return (String[]) ips.toArray(new String[] {});
      }
    } catch (SocketException e) {
View Full Code Here

    public void testListMyServiceIPV6() throws IOException {
        System.out.println("Unit Test: testListMyServiceIPV6()");
        JmDNS registry = null;
        try {
            InetAddress address = InetAddress.getLocalHost();
            NetworkInterface interfaze = NetworkInterface.getByInetAddress(address);
            for (Enumeration<InetAddress> iaenum = interfaze.getInetAddresses(); iaenum.hasMoreElements();) {
                InetAddress interfaceAddress = iaenum.nextElement();
                if (interfaceAddress instanceof Inet6Address) {
                    address = interfaceAddress;
                }
            }
View Full Code Here

TOP

Related Classes of java.net.NetworkInterface

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.