I want to get list of IP and MAC addresses of all devices assigned by router, for that I want to query router to find 'Dhcp Info' using Java in Android.
different routers provide different API. You'd better send something like a ping query to all IP adresses according to address assigned to you. Like if your IP is 192.168.0.18 then ping all IPs 192.168.0.1-192.168.0.255.
I guess this app is doing the same thing. Looks like he (the developer of the app) is also parsing the webpage to get the information.
In the images on the play store of the above app you can see he is displaying the whole router webpage and parsing the same page to get the information.
Check out the screenshot#2 of the app .
#VikramGiri To get lease duration in Android, try:
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.getDhcpInfo().leaseDuration;
This works if your router utilises DHCP. For utilised static IP address, the above code will always return zero instead of a number in milliseconds representing the lease duration.
The DhcpInfo class also provide other fields you might be interested in like: DNS addresses, IP addresses, gateway, netmask, etc. See here for more info.
Since you're new here, don't forget to tick answers if they are correct so others who read your post in the future will know that a given answer(s) is/are correct...
Related
I've tried the solution posted here How to configure a static IP address, netmask, gateway, DNS programmatically on Android 5.x (Lollipop) for Wi-Fi connection but have not been able to get it working.
It compiles and runs fine without crashing, but the IP address stays DHCP and the IP address is not set. Maybe it has to do with the way I am calling test() from another method? To call the test method it asks for an input parameter and the only this I have been able to get it to accept is 'this' so the method call would look like test(this).
Any help would be greatly appreciated.
EDIT:
I could be this part of the example that I screwed up:
WifiConfiguration wifiConf = ... /* Get Wifi configuration you want to update */
Does anyone know what the ... should be replaced with?
in Wifi Direct the group owner address always be 192.168.49.1 or it changes?
I'm new to android. please help me.
Thanks in advance.
cheers.....
Though I strongly believe that there should be no implementation where you need to directly rely on the IP Address of the GroupOwner, according to Android Source Code(Search for SERVER_ADDRESS in the file) the IP Address of the GroupOwner is 192.168.49.1 and is final and static.
Word of Caution: This might get changed anytime in the future, and hence, you must never rely on the value itself. You should always use isGroupOwner to find out whether a device is GroupOwner or not.
This seems to be IP address 192.168.49.1.Due to DHCP it will change-unless you have a static IP.
i have recently implement wifi direct into my project,my aim is pass string value between two wifidirect connected devices when some of my app condition satisfies.right now i have listed all peers and also made connection between the selected peer.now i need to pass String values to the connected devices..how can i pass string between two connected device. i have checked the [Wifi Direct chat][1]
[1]: https://github.com/life0fun/wifi-direct-chat project but it is very complicated.so any one suggest me any idea how can i pass the String values between two connected wifi device.(If code is needed i will post the code here)
you can use socket to connect between two peers in the same network.
for instance create a server socket on one of the peers on any port and then from the client side connect to that port on the other user . then you can use this socket connection to send strings, file whatever you want.
for starters i would recommend you employ the server socket on the group owner so it will be easier on your client side to get the ip of the peer(i.e group owner) using the groupOwnerAddress field provided by the api
refer to this -> http://www.oracle.com/technetwork/java/socket-140484.html
You can get text chat code from your installed SDK sample just goto
\sdk\samples\android-22\legacy\WiFiDirectServiceDiscovery
import that code into your eclipse, this is great sample in this text chating has been done nicely and code is too easy to understand.
I hope it will help you.
How do I get the MAC-Address of the network interface of an android device which doesn't have a Wifi-Interface (e.g. the android emulator)? WifiInfo obtained via the WifiManager returns null.
EDIT
To be more clear: I have to communicate with an existing network protocol (not designed by me) on the local network where I have to send the mac address of the communicating interface within the payload during a registration phase.
I'm going to take a leap and assume that you want this MAC address in order to establish a unique identifier for the device. Mac Addresses are not the way to do this.
There's an Android Developer Blog post titled "Identifying App Installations" which covers the topic of generating unique ID's fairly well, including the popular methods, and the pros/cons. It's definitely worth a read. Quite relevant to this post is the following quote:
It may be possible to retrieve a Mac address from a device’s WiFi or Bluetooth hardware. We do not recommend using this as a unique identifier. To start with, not all devices have WiFi. Also, if the WiFi is not turned on, the hardware may not report the Mac address.
The options available to you instead include TelephonyManager.getDeviceId(), android.os.Build.SERIAL, and Settings.Secure.ANDROID_ID, all of which are covered in more detail in the linked post.
Read /sys/class/net/[something]/address as a text file
But it's unlikely to be useful in the way you think.
See this post where I have submitted Utils.java example to provide pure-java implementations.
Utils.getMACAddress("wlan0");
Utils.getMACAddress("eth0");
Utils.getIPAddress(true); // IPv4
Utils.getIPAddress(false); // IPv6
What is the network interface you want the MAC address of? If there's no wifi, you certainly can't get the wifi device's MAC address. It represents the physical hardware and if that's not present, it simply doesn't exist.
To get wifi MAC of android device using adb:
adb shell getprop ril.wifi_macaddr
Use the following code in Java to get it programmatically:
Process p = Runtime.getRuntime.exec("adb", "shell", "getprop", "ril.wifi_macaddr")
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream());
String macAddress = br.readLine();
I need to many MAC address for one Device in Android.
is it possible to get many MAC Address from one device.?
plz help me.
Chick here for documentation mac address of WiFi controller.
Click here for documentation to find mac address of bluetooth adapter.
Edit1:
If you need hardware addresses of all the Wifi access points available to you.
You have scan for the networks (See here for API)
Iterate over results to get mac address of each. (See here for API)
code will look like
List<ScanResult> scanResults= wfManager.getScanResults();
for (ScanResult scanR: scanResults){
System.out.println(scanR.BSSID);
}