Does Wifi access points have an ip address? - android

I am trying to make an application which can connect from a mobile to a wifi controller. Planning to do a socket connection(multicast) ... The only values that i am able to get through the wifi android apis are SSID and BSSID.. Can anyone tell me if i am supposed to proceed with these values or am i supposed to connect with an IP address ? If i am supposed to connect with BSSID.. how do i go about it?

Wifi access points need not have an IP address, any more than wired switches and hubs do. However a large number do, as they also act on the IP layer as DHCP servers and network gateways.
What exactly are you trying to do? It sounds likely that it is not the Wifi access point proper that you need to talk to.
If it supports TCP and UDP, it will of course have an IP address. This will not be directly discoverable from the Wifi APIs, and you'll need some other means of discovering that. It's hard to say what exactly will be a reasonable method to do this without knowing what the AP is, and what services it provides.
Common ways of enumerating services provided on a network include DHCP; multicast DNS/DNS service discovery which is used by "Bonjour" and "Zeroconf"), SSDP and uPnP, and of course static configuration.
I'm not familiar enough with the Android network APIs to recommend anything, though http://jmdns.sourceforge.net/ appears to be a usable Java multicast DNS library.

Related

How to use Android_ID to communicate with other device?

My router shows
14:AA:BB:CC:DD:46 android-################ 192.168.3.112
AC:AA:BB:CC:FF:46 MY-LAPTOP 192.168.3.112
AC:AA:BB:CC:FF:AC NAS 192.168.3.112
Now if I use ftp://NAS/ it works, but
if I use ftp://android-################:7721/ it does not work, again ftp:/192.168.3.112:7721/ works, I don't understand what is the use of Android_ID then.
I thought since Android IP keeps varying on router we can find android by using Android_ID, but that's not the case.
Can anyone explain why is it happening?
Your Android device uses DHCP to get an IP address from the router on your network. While a router will try to use the same IP address across sessions, there's no guarantee you'll always be handed the same IP address. You generally do not want to make any assumptions about it not changing.
Assuming you have client software that's trying to talk to a service running on the Android device you need to implement some sort of network discovery mechanism. Android has a mechanism in the SDK that uses mDNS called "NSD". See https://developer.android.com/training/connect-devices-wirelessly/nsd. You could also use UDP broadcast.
"android-####" is a local hostname. Unless you have registered your Android device with a DNS server serving your local network you need to use IP addresses (and in that case you'd need to configure your router to also give your Android device the same IP address).

NAT punch-through on mobile network for p2p model?

I am writing a p2p messaging Android app, and I'm trying to solve the problem of NAT on mobile networks. I cannot currently find a way for a device to connect to another listening device on a 3G/4G network due to the carrier's NAT service.
I have heard of a few NAT punch-through methods, but a lot of those involve using some sort of centralized server as a mediator. I am trying to use a completely decentralized p2p approach to accomplish this task.
Are there any feasible ways of allowing a device on a mobile network to be publicly addressable?
Thanks!
No, it is not possible. Most of the time, subscribers with IP addresses NATed are behind NAT444 and many subscribers are anycasted ( subscribers have the same IP on their mobile phone, but nated behind a different NAT devices). And 2 anycasted suscribers cannot communicate together.
The only way left you is to open a VPN to get a real IP of Internet Public.
My suggestion would be: Do not use VPN for IPv4 ! Use VPN to get a real IPV6 to your mobile phone application, and build your p2p application over IPv6.
You are fighting with very old problem that drove IETF to build IPv6.
So, go to IPv6, and forget ipv4.
The ONLY good solution for your problem is to build your app over IPv6, and your app has to bring the ipv6 tunnel to the phone.

Change WiFi-Direct IP range? Force IPv6 in Android WiFi-Direct?

I have two Android KitKat phones, both are running WiFi-Direct groups as Group Owners, let's call them GO1 and GO2
I managed to connect GO1 as a legacy client to GO2 without breaking any of the (previously set) wifi-direct groups.
The problem is that, as you might know, the GO IP address is hardcoded in Android source, and is set to 192.168.49.1
Therefore, both of my devices, GO1 and GO2 have the same IP address (**)... each on his local network.
My app is both client and server at the same time. But both networks are using the same IP range (192.168.49.XXX), which, apparently, I cannot change.
As a result I cannot create a TCP connection between them if they are both hosting a WiFi-Direct Group, since any device will connect to itself when trying to connect to 192.168.49.1
So the questions are:
Is there a way to change the IP range used in Wifi-Direct?
Is there a way to use IPv6 instead of IPv4 in Wifi-Direct?
Can any of this be done without rooting the phone?
Any other suggestion?
** : Actually, because GO1 is connecting as a legacy client to GO2, then GO1 is known as 192.168.49.227 (for example) to GO2 and GO2 is known as 192.168.49.1 to GO1. But because GO1 is ALSO a GO, it also known as 192.168.49.1 to his clients (and itself).
A way to get around this without rooting the phone is to send your packets via multicast UDP*. These packets will make it from GO1 to GO2.
There are some side effects to this:
To use this for networking you must perform encapsulation and routing at the OSI Application level (not efficient).
You will also need to route based on MAC addresses since every device has the same 192.168.49.1 address.
"It is important to note that the multicast socket encapsulates a one-to-many unicast communication and, as a result of this, cannot fully utilize the total available WiFi and WiFi Direct bandwidth" *
Something else worth noting:
As you scale up the number of GOs, you will run into a problem of all nodes operating on the same wifi channel. This isn't a problem with a few devices, but with hundreds of devices, it will be a huge problem.
*This method was mentioned in Colin Funai, Cristiano Tapparello, and Wendi Heinzelman paper titled "Supporting Multi-hop Device-to-Device Networks Through WiFi Direct Multi-group Networking" found here: https://arxiv.org/pdf/1601.00028.pdf
There is no way to change the IP range because as you have correctly pointed out, it is hardcoded in the Android Wi-Fi Direct system service. Personally, I am not aware of IPv6 being enabled on the Wi-Fi P2P interface, and even if it was, it would likely be a hardcoded IPv6 address.
If GO1 and GO2, must be connected to each other whilst both in GO mode, then perhaps look at using Bluetooth or some other transport to allow them to communicate. If communication between GO1 and GO2 can be delayed, then cache whatever information is to be exchanged, and send it between these two devices when one can be the client of the other, e.g. when GO1 can stop being a GO and can be a client of GO2.

Can I check the number of users (or mobile phones) connected to wifi network

I have read these Getting Started with WiFi on Android. Implemented Marakana's tutorial for basic wifi functionalities.
But my question is: Is there a way to find the number of users connected to a wifi network?
If it can be done, kindly share a link or resources.
If it cant be done, kindly provide some detail, why not?
Thank you,
Getting a list of computers on a network is inherently an unreliable proposition, wifi or wired.
There are three common approaches: a discovery protocol, scanning, and passive listening.
Discovery protocols (such as LLDP from the UPnP framework) work very well for devices that support them. Occasionally also for devices that don't. They don't work at all if firewalls block them, or if switches or wifi access points are configured not to allow traffic between devices.
Scanning means, sending a probe (such as a ping) to each possible IP address. This is something many intrusion detection devices block, and many wifi access points will also prevent you from sending a ping to another device. Also, scanning is entirely unfeasible in IPv6 because each network has billions of IP addresses to probe, rather than the usual 254 in IPv4.
Passive listening means, simply paying attention to the layer-2 traffic on the network, and building a table of MAC addresses based on the ARP traffic (or all traffic). That only works reliably if you have a wired network with a hub - switches don't forward all layer 2 traffic everywhere (although the ARP messages you need most are usually broadcast and available). WiFi isolation may also prevent you from getting enough layer 2 traffic.

Socket programming WiFi issue

I am implementing a mobile chat application, I am using socket connection for implementing p2p connectivity. My chat is working fine with android devices. My issue is I can connect a device in 3g network or with in the same WiFi network but the connection is not working when a device form outside WiFi try to connect a device in the WiFi network. I know it's because of the local IP of the device assigned by the WiFi. How can I root and connect a device in the WiFi?
Sounds more like a router settings issue, than an app issue (meaning that users of your app would need to do this for their own networks as well).
Your wifi router needs to know how to forward communication to your device. So say that your app is connecting on port 1234, then you need to tell your router to forward communication from the outside on port 1234 to the internal IP of your phone in your wifi network.
The phone that is outside of the network should target your network's external IP and port 1234.
Sajan, your issue is not only an IP mapping issue, but also a NAT traversal issue. It is not always possible to punch holes in NATs. And when it is, it must be done with some sophisticated techniques including a super peer located outside of your wifi/lan which will read the translated address from your inside peer.
Unless you are using UDP and the NAT is friendly, it is not possible to send TCP communication directly to the inside peer. In most case, you'll have to check what is possible with the NAT, and if there is something possible, you'll need to perform mapping prediction and tell both peer to attempt com on predicted IP addresses.
That's valid if you don't want you users to have to configure their NATs. And even in that case, such configuration will not always be enough (if there are cascades of NATs, or proxies for example).

Categories

Resources