System InetAddress : Connectivity « Network « Android






System InetAddress

    
//package ro.ui.pttdroid.util;

import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.LinkedList;

import android.util.Log;

class PhoneIPs {
  static private LinkedList<InetAddress> inetAddresses = new LinkedList<InetAddress>(); 

  public static void load() {
    inetAddresses.clear();
    try {
      Enumeration<NetworkInterface> networkInterfaceEnum = NetworkInterface.getNetworkInterfaces();
      
      while(networkInterfaceEnum.hasMoreElements()) {                
        Enumeration<InetAddress> inetAddresseEnum = networkInterfaceEnum.nextElement().getInetAddresses();
        
        while(inetAddresseEnum.hasMoreElements()) {
          inetAddresses.add(inetAddresseEnum.nextElement());
        }
      }
    }
    catch(IOException e) {
      Log.d("MyNetworkInterfaces", e.toString());
    }
  }
  
  public static boolean contains(InetAddress addr) {
    return inetAddresses.contains(addr);
  }
  
}

   
    
    
    
  








Related examples in the same category

1.is Network Available
2.is Net Connected
3.Connectivity Tester
4.Is Android connected to your server
5.Is connected
6.Is Connected To Internet