Socket connection from PC to Android emulator - android

So here's what I'm trying to do: I have an Android app that uses a ServerSocket and I need to connect to this socket from my computer.
I've tried to get my IP address using adb shell ifconfig and I can ping this IP from the emulator's shell but I can't ping it from my computer's terminal.
In other words, how can I use Postman to connect on my emulator's web server?

I've found the solution. It seems that if you want to communicate from your computer to your emulator, the IP address to use is 127.0.0.1 and you need to do some port forwarding using ADB in command line.
For example if you emulator is running a server on port 8080
adb forward tcp:8080 tcp:8080
Then call it with localhost:8080

Related

Run frida-script on frida-server with custom port

I'm trying to bypass SSL pinning.
I used this tutorial:
https://httptoolkit.com/blog/frida-certificate-pinning/
Create frida-server and run it:
adb shell "/data/local/tmp/sus_app -l 0.0.0.0:11124"
And then run frida-script:
frida -H 127.0.0.1:11124 -l agulaguglag.js -f "com.someApp.android"
Get:
Also trying hosts from this question (How to change frida server port in android?).
Same result.
Which host should i use?
On the PC side you try to connect 127.0.0.1:11124, this means you are trying to connect to a local server port.
As frida-server is running on the Android device and not on your PC you need something that connects both sides.
The easiest way would be to forward TCP port 11124 from Android to TCP port 11124 on the PC use adb:
adb forward tcp:11124 tcp:11124

Port forwarding using adb shell commands

I want to connect with my linux pc through ssh to my linux device which is connected via USB to my android device(Only using adb shell commands)
For now I'm doing it using two apps which is installed on my android device:
1. Network IP scanner, which gives me the IP of the target device.
2. FwdPortForwardingApp (https://github.com/elixsr/FwdPortForwardingApp)
With that App I perform port forwarding using BOTH udp and tcp protocols from wlan0 on port 2222 to the target IP I got from the network IP scanner on port 22.
I want to do it using only adb shell commands, how can I do it?
Tried adb forward tcp:2222 tcp:22 and adb reverse tcp:2222 tcp:22 which didn't help
Expected to perform ssh using port 2222 directly to my device using only adb shell commands (Cause I want to create a script which will perform all the commands together without using the android device)

Nexus 9 (OS -6) adb connection over tcp not Working

After upgrading my device to Marshmallow, I am unable to connect my device on tcpip for wifi debugging (It used to work on Lollipop). IP is my device IP address.
platform-tools>adb connect IP:5555
I am getting below message
unable to connect to IP:5555
I also tried to connect on 7612 port.
5555 is the port number which is not used while connecting. Connection takes place in to steps:
Set port on which connection is to be stablished(in this case 5555)
Connect to the device using it's IP address.
So let's say your device IP is 192.168.1.1 and you want to connect over port 5555,
adb tcpip 5555
adb connect 192.168.1.1
Try the following
Make sure that Aggressive Wi-Fi to Cellular handover under Networking section in the device's developer options is turned off.
ping continuously from your pc to the device to make sure it's not in network idle mode
ping -t 192.168.1.10 (windows cmd), unlock the device and even try to surf to some
website just to make it get out of the network idle.
If ping doesn't work, turn off / on Android Wifi and go back to step 2.
When it replies to the ping, connect it via usb, and:
adb usb
adb tcpip 5555
adb connect 192.168.10.1:5555
In case it's still not connected, try to switch the usb connection mode as MTP / PTP /
Camera while the device is connected through usb and repeat these steps over again...
If the above points are not working please try running adb as admin. For Ubuntu -
sudo adb start-server
as stated here

telnet to 10.0.2.15:2323 - The Emulator IP Address

I am trying the PJSIP on the Android and to emulate the commands on the Android, it asks us to telnet to 10.0.2.15:2323.
But when I try to telnet from my terminal it doesn't allow to telnet.
What I found was telnet localhost 5554, it works to access the emulator.
Please how can I telnet to 10.0.2.15:2323?
Just use a space instead of a : between the ip-addr and the port
telnet 10.0.2.15 2323
Make sure the adb server is running
adb start-server
Telnet to the port on which the adb server is listening (typically 5554).
telnet localhost 5554
Then on the telnet prompt, add a new redirection. The adb server will listens to an additional port 5000 and forward the traffic to the telnet service on port 2323 on the emulator.
redir add tcp:5000:2323
Now one can telnet to localhost with port 5000, adb server forwards this to the telnet server on the emulator
telnet localhost 5000

How to set up ADB for remote machine development and local device deployment

My scenario is this: I telework from home and log into my work machine via Windows Remote Desktop. I use Eclipse as my development environment for Android apps on my work computer.
Using ADB, I would like to be able to deploy apps from my work computer to a device on my home network, for scenarios where the emulator doesn't do the app justice.
I found this post, which discuss a very similar scenario, with the exception of deploying to an emulator running on a local PC, instead of deploying to a local device:
http://www.41post.com/5003/programming/android-adb-remote-emulator-access
I'm trying to take the same steps, but figure out how to target a local device on my home WiFi network & tethered to my local home PC, instead of the local emulator.
Right now, I have the remote PC set up to try and connect to my public router IP on port 5585 - but in my router, what IP/port do I forward this to to connect to the local device?
In the example using the emulator, they forward to the local PC address where the emulator is running and port 5555, and adb is not running on the local PC. I have configured my router to forward to my device IP, with the device on WiFi, as well as my local PC IP where the device is tethered.
However in both scenarios, when I try adb connect <routerIP>:5585 on my remote PC, it gives me an error unable to connect to <routerIP>:5585:5585. I get the same response when trying to forward to/listen to other ports. I'm not getting any security errors in the router log, so it appears the port forwarding is working.
Questions:
What local IP/port number should I forward to when configuring port forwarding on my local network to connect to the local device using the remote adb instance?
Should I be targeting the local PC IP that the device is tethered to, or the local device IP?
If I target the local device IP, what port number should I forward to?
Do I need adb running on my local PC?
I had a similar situation. I work on a remote desktop for development but my android device is connected to my local laptop. I wanted to be able to use adb and the android plugin in eclipse on the remote desktop and connect to the device attached to my laptop. After searching on the internet and not finding anything that really helped, I decided to write a port forwarder that would do the trick. You can find it here. I hope it will be helpful to other people as well.
Beginning Android 4.3 you can:
Make adb server listen on all interfaces. You have two options:
Make gListen=1 and recompile adb (I have compiled it on Linux-x64 machine for you and put it here)
Start adb server with -a parameter: adb -a -P 5037 fork-server server&
Use adb on your remote machine with extra parameter, e.g. adb -H <remote_host> shell
Another setup for remote host + local device testing. This will be useful for lots of people working from home on a laptop, connected to their development host machine still in the office. Note that I assume both devhost/laptop are both running Unix, but other OSes will be able to run the commands on the command prompt/shell.
# Kill old adb server.
devhost$ adb kill-server
# Activate adb server on client
laptop$ adb start-server
# Start ssh tunnel. Hide/minimize this window not to close it by accident
laptop$ ssh -XC -R 5037:localhost:5037 <your devhost machine>
# Should work by now with the local device connected to the laptop
devhost$ adb logcat
You can solve the issue by port forwarding.
Download Secure Shell app from the Chrome app store
Connect to your machine (step-by-step setup)
In this connection, disable adb server: adb kill-server
Create a new port forwarding connection (same as a regular connection, but set the SSH Arguments field to: -N -R 5037:localhost:5037)
On your laptop, open up a terminal and enable adb server: adb start-server
Probably there is a simpler solution, providing the device, the local and remote machine belong to the same network.
Let's say your device has a certain IP over the network and let's say you decide to use your preferred PORT: well, you can do the following steps.
On the machine where the device is plugged please run:
adb devices
adb tcpip <PORT>
Example of PORT is 5555.
On the remote machine you need to deactivate 'Discover USB devices', 'Discover network targets' and 'Port forwarding' and then run:
adb connect IP:PORT
*IP is your android device IP(not the first machine IP) which can get from adb shell ip -f inet addr
And you are ready to debug on remote machine.
This is how I made it work from host macOS with emulator to macOS client.
A: One line command
On host of emulator
socat tcp-l:5560 tcp:localhost:5559
On client
adb connect <IP>:5560
B: With a tunnel
on host
host$ adb kill-server
host$ adb -a nodaemon server
on client
client$ adb kill-server
client$ ssh -L 5037:localhost:5037 <host-IP>
open second shell on client
client$ adb kill-server # I observe first it kills client adb
client$ adb kill-server # then it kills server adb, do it maybe once more
client$ adb devices # show devices on server now
Now I see host emulator in Android Studio as well
My situation required using a VM that is on a different network, but that I rmd into (an Azure VM). The VM and my local laptop are both running Windows 10. First, I had to install USB Redirector RDP Edition on my local machine (costs $80, but there might be free alternatives), then install the Google Android USB driver on the VM and the Universal Adb Driver on the VM. I'm now able to load an Android Studio App the project in Android Studio on the VM, connect an Android device on my laptop, and debug the app on the device.

Categories

Resources