Genymobile / gnirehtet

Gnirehtet provides reverse tethering for Android
Apache License 2.0
6.23k stars 571 forks source link

Can I communicate host => phone? #105

Closed valgusk closed 6 years ago

valgusk commented 6 years ago

Is it possible to eg. ping the phone with this connection? Or is it completely inaccessible from the host OS?

rom1v commented 6 years ago

Every input event (keyboard and mouse) sends an event from the host to the device, so the host communicates with the device. What do you want to do exactly?

valgusk commented 6 years ago

OK, I am confused. Since I do not understand the answer, the question must have been very stupid. Sorry about that and please delete/close the issue

rom1v commented 6 years ago

I do not understand the answer

That's probably because I did not understand the question. This does not imply that the question is stupid :)

What do you want to do?

PhilLab commented 6 years ago

@rom1v it looks like your answer is more true for https://github.com/Genymobile/scrcpy , not to this project here, though quite related. I think I have the same question as @valgusk so I will try to elaborate:

At which ip can my host machine reach the Android device? When my app lists the device ips using NetworkInterface.getNetworkInterfaces(), I get the IP 10.0.0.2 but I can't ping this from my host PC - it is just not reachable. Also, if my app opens a socket at a specific port, 10.0.0.2:9999, I cannot establish a connection as well. But it does work over WiFi.

If my app calls a server running on my host machine, it reaches it under the same IP I would use when having WiFi (kudos for that, very awesome!), but the server reports the client connection having the ip of the host - so I can't identify the true ip of Android.

If my app calls a server on my host machine not using the wifi IP but 10.0.2.2, the server reports the client to have the ip 127.0.0.1 - which obviously also does not let ports trough

Do we have to configure something like a port forwarding in gnirehtet and if yes, how can you do that?

rom1v commented 6 years ago

it looks like your answer is more true for https://github.com/Genymobile/scrcpy , not to this project here, though quite related.

Ah, that's why I did not understand the question. Sorry @valgusk! Thank you for explaining @PhilLab :wink:

At which ip can my host machine reach the Android device?

It can't directly, they're not on the "same network".

If you want to reach a specific port on the device, you need to enable adb port forwarding. For example:

adb forward tcp:1234 tcp:5678

Then, from your host, when you connect to localhost:1234, it will connect to the device on port 5678.

But it does work over WiFi.

Yes, that's expected.

rom1v commented 6 years ago

Note that it is also possible to reverse tether only specific routes. For example:

./gnirehtet start -r 8.8.8.8,192.168.0.0/24

Only 8.8.8.8 and 192.168.0.* will be reverse tether, the others will use the device connection normally.

KeithScheiwiller commented 5 years ago

@rom1v Sorry for bumping this old issue. Just a quick question on this. Would it be technically feasible to tweak gnirehtet so that it is bidirectional? In other words, could the host and phone be made to be on the same "network"?

If it is possible, I might look into implementing it. But I'm not completely sure how gnirehtet actually works, so it might actually not even be possible. Thanks!

rom1v commented 5 years ago

In other words, could the host and phone be made to be on the same "network"?

No, I don't think so.