Android : forwarding of packets to an IP address - android

I have an Android device. I need to forward packets arriving at the external IP to an internal IP to which Android is connected to.
I would like to know if I can write an App to enable this forwarding.
Also, if this doesn't what is the conventional way this is done. If I should use some scripts where should I place them??
And oh, can I test this using an android emulator??
Thanks.

It is may be possible to emulate a behavior like port forwarding but not routing for non rooted devices.
Also if you want to forward traffic from the mobile network to the wlan this is so far I know not possible. Android switches the connetion between mobile network and wlan. It is not possible to use both. Except some hot spot use cases.

Related

Accessing WiFi LAN (no gateway) and mobile network simultaneously

I'm aware it's been asked before (with limited or no solution) but I haven't seen any recent updates and I think my scenario is unique so I'll start a new thread.
I have a Raspberry Pi and it's functioning as a hot spot among other things. By design, DHCP isn't handing out a default gateway. My use case is one or more devices interacting with the Pi as a server.
One of the connected devices will be a mobile device(edit: running a custom app of my design which is part of the total solution), and that device will maintain its cellular connection, not for tethering or routing but so that the application can access internal and external resources simultaneously.
Currently:
IOS: This works exactly as I expect on IOS - it senses that the WiFi network doesn't have a default gateway and sends external traffic over cell.
Android: This doesn't work at all. Android stubbornly sees WiFi connected and disables cellular, even with no default gateway.
Windows Phone: Kind of a hybrid. Both networks stay up but my scenario has a DNS entry in public DNS, and a public site links to a resource on the Pi. If I link to the resource directly using the WiFi IP address of the Pi, it works fine (although this causes other issues related to security). If I link via a FQDN, I'm actually not sure what's going on. It doesn't resolve from the web browser although every networking utility I've installed on the phone for troubleshooting correctly resolves the FQDN to the Pi address via DNS.
Hope this makes sense. The question: How can I enable this functionality across the board in 2015? :) For my purposes, the Pi as a private nonroutable hotspot works better than WiFi direct or Bluetooth. And remember I'm not asking the phone to ROUTE; I need my custom application to be able to simultaneously connect to the Pi and to the public Internet. I want all the phones to do what IOS does in this regard.
My current scenario is the Pi hosting a web page (among other things) and that's my preference, but can this even be solved natively?
You say that this is not a tethering or routing situation, but if you think about it, it really is both.
It is routing because the traffic from the phone needs to be routed to one of the two interfaces. There may not be routing through the phone, but it's still a routing problem. Fortunately, it seems that the routing part is working on all three platforms.
It is also an unusual form of tethering. The only differences are that traffic does not originate from the Pi, but from the phone, and that the Pi rather than the phone acts as the access point.
Thinking of it in terms of tethering is important because it shows that the Android CAN have WiFi and cellular active at the same time (at least in hotspot mode, but probably also in client mode). In this respect, my answer isn't complete - I can't tell you HOW to accomplish that.
As for the Windows phone problem you mentioned: in order to troubleshoot that, first identify where the DNS server is located that knows about the Pi's FQDN. Does a public DNS server know about it, even though it is obviously on a private network?
There are two possible explanations for your observation:
There is no public DNS server that even knows this FQDN. In that case, IOS is probably using something like mDNS to locate the Raspberry Pi.
There is a public DNS server that knows this FQDN. In that case, maybe Windows Phone checks the DNS reply for martians and rejects it, thinking that it is an attack.
Either way, what you'd really need is to have two separate DNS infrastructures. One way to do this is to include a small DNS server (dnsmasq maybe) with your app, and configure a forwarder for the zone with the Pi's FQDN to forward to the Pi's IP address (which would have to be hardcoded, obviously). All other requests should go to the normal DNS servers.
Another way might be to not use DNS at all, but use the hosts file instead.
For Android phone you can use application named "WiFi & Mobile Data Switch" (https://play.google.com/store/apps/details?id=com.totemsoft.wifimd). For me it solves the problem of simultaneous connecting to internet (via mobile data) and to local network (via WiFi, internet is inaccessible via WiFi). This applications works ok on Samsung Galaxy A8. I hope, my comment helps to somebody.

Is it possible to emulate a network between my device and my desktop?

I'm developing an app and I need to use my network to access some webservices. I was connecting on WiFi and it was ok but I think that a system administrator should have blocked the incoming connections in my desktop.
I want to know if I can find an app to simulate a network between my desktop ( Windows 7 ) and my Android device.
Do you know if it's possible? How?
If somebody put a locket, than has a reason. Easier to talk with him. If he don't want... than use an USB to Wi-fi adapter and the WI-FI connection is ready :)

How can two machines detect each other when their ips keep changing?

Let me describe what I want to achieve and where I am stuck. It is okay to suggest an entirely different alternative.
I have an Android phone with NFC feature.
I have a macbook pro.
A wifi network.
Whenever I tap my phone on a certain NFC tag I want my Macbook to run a certain script.
So I did the following
An android application that is invoked whenever the device senses a particular NFC tag.
My Macbook runs a NodeJS HTTP server
Android app sends an HTTP request to NodeJS, NodeJS then invokes whatever script I wanted to run.
This setup works perfectly at my home where I can Set the IP address of my Macbook to whatever I want. But i want the same setup to work transparently when I am in starbucks (or workplace) and both my Android and Macbook are on the same Wifi network. (I dont want to enter the IP addresses manually).
When I was halfway through I realized that I could have used bluetooth feature on the Macbook but then I will probably have to write a sophisticated program on macbook to listen to the Android device and accept commands.
On Android, use Network Service Discovery. If you're using an earlier target, jmDNS is your friend. I have only used this to allow android devices to find each other, but this should be compatible with bonjour service on your Mac.
Solution #1
Use a network service discovery technology. I would perhaps suggest Zero Config which Apple implements as "Bonjour"
Solution #2
Have a third device with a known IP address for bookkeeping the other devices' IP (essentially what DNS is)
Solution #3
Setup your WiFi network to have static IPs : allocating predefined IPs to computer with specific MAC addresses (that way clients can still have "DHCP" but the router would always allocate the same local IP)
I'd look into dynamic dns. You can use that to automatically update dns names for a computer that changes IP addresses.

WiFi-Direct communication between Mac/Windows and Android

Is it possible to let an Android (>4.0) device establish a WiFi-Direct connection with a Mac OS or Windows device?
According to the Wifi-Direct Docs the protocol allows:
Android 4.0 (API level 14) or later devices with the appropriate hardware to connect directly to each other via Wi-Fi
It doesn't look like Google provides this functionality via the API. Although WiFi-Direct isn't a proprietary protocol and could be implemented for any platform. There are a few posts around the web of people trying to get Wifi-Direct to work under windows:
Broadcast message from Desktop PC to Android Device using WIFI connectivity
https://superuser.com/questions/417888/how-do-i-connect-a-laptop-running-windows-7-to-an-android-phone-using-wifi-direct
http://www.intel.com/content/www/us/en/wireless-products/my-wifi-technology.html
http://androidforums.com/android-lounge/552970-howto-wifi-direct-use-your-laptop-desktop-softap-android-reverse-tethering.html
All you need is to use java.net.Socket. Depends on what do you mean by establish direct connection. TCP connection is established when on destination device (windows or mac) you open listening socket by ServerSocket. On other device you can use Socket with destination address. Of course, windows or mac box will propably have to open that port in firewall.
I guess what you actually need to know is how to get name of target computer or how to discover computers on local network. Unfortunately, it does not depend on android version I think. You should check http://en.wikipedia.org/wiki/Zero_configuration_networking about some hints. I fear there might be problem in need to open privileged port on android, as normally you have to be root for that. And that would require rooted android.
Of course you should specify what do you intend with that direct connection and what software do you need. If both ends have your application, you can just open any not allocated and unpriviledged port on android. Use UDP to broadcast periodically name of android device (propably ask user to enter name of his device). Use multicast to send requests, and receive replies the same way. Multicast sending and receiving would require your application on android and on windows and on mac also. Now you can read from multicast application what type of machine it is, and what local port it left open for your direct connection. From source of udp message you know where to connect.
You may use some framework to speed things up. All this require some knowledge about networking, but I don't know simpler and well working solution. Unless you provide details about what is your direct connection to do.

View android network traffic via wireshark

I'm trying to view the protocol on an app I'm using to see how it works but I can't find any traffic (except netbios traffic) coming from my Android phone (HTC Aria).
I don't have any way of getting any hardware for this and i'm using the phone on my router's wifi and the PC is directly connected to my switch.
you probably want to use something like Charles SSL...point your phone at some kind of Proxy server that captures traffic.
If you connect the phone and your computer w/ Wireshark to the same network via a router (not a switch which won't show you shared traffic), you can use Wireshark to monitor all the traffic to you phone.
I'm not sure how you are attempting to use WireShark in this scenario, but what you should do is use a packet sniffer like Shark for Root on your android phone.

Categories

Resources