Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String getIpAddress() {
- try {
- for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
- NetworkInterface intf = (NetworkInterface) en.nextElement();
- for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
- InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement();
- if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
- String ipAddress = inetAddress.getHostAddress().toString();
- Log.e("IP address", "" + ipAddress);
- return ipAddress;
- }
- }
- }
- } catch (SocketException ex) {
- Log.e("MASOOM", ex.toString());
- }
- return null;
- }
- public String getIpAddress(){
- WifiManager wifiManager = (WifiManager) this.getSystemService(WIFI_SERVICE);
- int ipAddress = wifiManager.getConnectionInfo().getIpAddress();
- return String.format("%d.%d.%d.%d", (ipAddress & 0xff), (ipAddress >> 8 & 0xff),(ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement