22016

How to find LAN ip address of android device?

Question:

If wifi of device is connected, I assume the device has an LAN IP address assigned presumably by a dhcp running on a router.

How can find it what's the LAN ip address (not the external ip) on the wifi interface ?

Thanks,

Answer1:

<a href="http://developer.android.com/reference/java/net/NetworkInterface.html" rel="nofollow">NetworkInterface</a> will help you:

String ipAddress = null; try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { ipAddress = inetAddress.getHostAddress().toString(); } } } } catch (SocketException ex) {}

Recommend

  • Can I parse a String to Time in java
  • Convert Json to Xml In Android [closed]
  • protobuf with inheritance?
  • CKEditor 4 - how to add font family and font size controls to the toolbar
  • how to implement OnClickListener for custom ViewHolder in my recycler view?
  • Non-blocking mlock()
  • Hosting existing node.js apps on Windows Azure
  • Share dialog: “Sorry, sharing is unavailable at this time. Please try again later.”
  • Google Cloud Dataflow consume external source
  • How to add GeoJSON(MultiLineString) layer to a Google Map
  • Creating the shortest possible case-insensitive verification number
  • Different Realm Configurations Appearing in Swift App
  • Microsoft speech API 5.1, 5.3?
  • Rxjs Observable Lifecycle
  • Best way to send continuous data in Java using Netty
  • Bokeh Mapping Counties
  • Selenium 2 : finding web element locators programatically
  • How to Enable Systemd service in openshift/jenkins-1-centos7 docker container?
  • Replacing ui router 0.2 with 1.0.0
  • JS showModalDialog not working in chrome as modal
  • How to create wsdl from xsd
  • Spongycastle is missing many algorithms when loaded on android
  • Getting/building the SQL (with parameters) from NHibernate 3.2
  • yii rewrite url with many sub categories
  • Multiple canvases (pages) in Fabric.js
  • Request Access Token in Postman for Azure Function App protected by Azure AD B2C
  • Stop an element moving with padding on hover
  • time column in sqlite using gorm
  • When to use the tag in the head and body section of a html page? [duplicate]
  • How to define something in JavaScript [closed]
  • Neo4j…how to get a visual representation of my data?
  • Bitrate JWplayer
  • Make checkout phone field optional for specific countries in WooCommerce
  • calling IO Operations from thread in ruby c extension will cause ruby to hang
  • Angular 4: Responsive Grid List
  • Accessing Arguments, Workflow Variables from custom activities
  • Write to .csv file with PHP (Commas in Data Error)