Click here to Skip to main content
15,887,746 members
Articles / Mobile Apps / Android

Android Usb Port Forwarding

Rate me:
Please Sign up or sign in to vote.
4.88/5 (52 votes)
26 Dec 2011CPOL4 min read 1.8M   201.8K   155   315
This tool creates an USB tunnel between the android and the PC. The tunnel will forward communications to and from the host.

Download Windows part : AndroidTool.zip - 3.2 MB
Download Android part Tracetool_service.zip - 99.04 KB

(See article in Portuguese here)

Important Update :

For rooted phone, you can use my other program (not yet on codeproject) :

Android reverse tethering : http://forum.xda-developers.com/showthread.php?t=1371345 

Introduction   

The Android architecture does not allow to start communication from the Android to the host through the USB cable.The opposite is possible, using the Google "Android Debug Bridge" (ADB in short).    

This tool will act as a tunnel between the Android client application and the host server. It is a software implementation of a router doing IP port forwarding.

global.png

On the Host part, you have to declare the ports you want to be opened on the Android and the tunnel will transfer communications between the android and the host. The host can be any server on the network or your local host. 

Prerequisits   

  • Enable "Usb debuging" on your Android : Go to parameters / Applications / Development and check  "Usb debuging" 
  • Install "Usb Tunnel" on your Android (see donwnload link on top of the article) or from the market :
     
  • Screenshot - market.jpg

  • Install the host windows application (see download link on top of the article) or this skydrive link or this GDoc link   
  • On the configuration panel, enter the path to the ADB program. ADB is part of the Android SDK. The installation includes the minimum files required.
  • Add tunnels. Each tunnel is composed of a name, an Android port (low port like 80 can't be used), a host IP and a host port (can be different from the android port)  
 config.png

HTTP proxy 

If Tethering is a technology that allows you to use the mobile internet connection on your PC, this tool gives you the opposite. It's a sort of Reverse Tethering.   

You can now surf on your mobile (using the internet connection on your PC) through the Usb tunnel and via a proxy. 

If you are on a company network, ask your administrator what IP adddress and port he is using for the proxy. In some cases it can be the default gateway (run ipconfig command at the DOS prompt to find out what the default gateway is). 

If you are on a private network and you have no clue about the proxy adress and port, you can use a public proxy (do search for "Public proxy" on the internet). To help you out, here is link to a list of proxies. 

Another possibility is to install a local http proxy server like squid.  

Step 1 : configure the windows part. Since low ports can't be used, you should use a different high port for the android and another port for the host.  

Sample configuration for a company network : (192.168.xxx.xxx) on port 80 

 httpProxy.png     

Sample configuration for a public internet proxy on port 8080 

httpProxy2.png

Step 2 : Connect he USB cable (of course).  Click the refresh button to display your device in the device list then click connect. The Android Usb tunnel service will start in the background. A connection icon will be added on the notification pannel.  

Step 3 : Setup your browser to use a proxy. Depending on the version of your Android OS, it's possible to define a http proxy in the advanced wifi settings menu (Not tested, available in some Android, but not all). 

Normal Chrome browser

  • I didn't find a way to get it working. Forget about TransparentProxy, ProxyDroid or AsProxy. that require Root and don't work  

Opera mobile 

  • Enter opera:config in the address bar 
  • Expand the proxy line  
  • HTTP server : 127.0.0.1:8080  
  • HTTPS server : 127.0.0.1:8080  
  • Use HTTP : checked 
  • Use HTTPS : checked 
  • Click "Save" 

Firefox Mobile

  • Enter about:config in the address bar 
  • In the search filter (below address bar), enter "proxy"
  • Set network.proxy.http to 127.0.0.1 
  • Set network.proxy.http_port to 8080  
  • Set network.proxy.type to 1 (Manual). Default is 5 (system)  

Skyfire

  •  I didn't find a way to get it working. 

Step 4 : Enjoy! enter any URL on your browser. Your firewall may detect that AndroidTool.exe is trying to access the internet. Give him the rights to access the proxy. 

running.png 

In this screenshot, you can see the number of active connections , closed connections, total bytes transfered (to and from) 

I checked with an internet speed test. It's just a little bit slower. 

History 

May 2011 : 

   First version  

Decembre 2011 : For rooted phone, you can use my other program (not yet on codeproject) :

   Android reverse tethering : http://forum.xda-developers.com/showthread.php?t=1371345 


 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionGot it working on Galaxy SII on my windows 7 (usb to webserver host) Pin
Member 859506012-Aug-13 4:52
Member 859506012-Aug-13 4:52 
AnswerRe: Got it working on Galaxy SII on my windows 7 (usb to webserver host) Pin
Member 1022917824-Aug-13 1:37
Member 1022917824-Aug-13 1:37 
GeneralRe: Got it working on Galaxy SII on my windows 7 (usb to webserver host) Pin
Thierry Parent24-Aug-13 21:36
Thierry Parent24-Aug-13 21:36 
AnswerRe: Got it working on Galaxy SII on my windows 7 (usb to webserver host) Pin
AATIF ALI KHAN7-Feb-14 1:42
AATIF ALI KHAN7-Feb-14 1:42 
QuestionIp webcam port Pin
Stefan Novakovic8-Aug-13 4:23
Stefan Novakovic8-Aug-13 4:23 
QuestionIn what mode i have to connect ? Pin
Nandha Nandy26-Jul-13 19:22
Nandha Nandy26-Jul-13 19:22 
QuestionWant to understand. Pin
Никита Чехомов26-Jun-13 20:48
Никита Чехомов26-Jun-13 20:48 
AnswerRe: Want to understand. Pin
Thierry Parent26-Jun-13 21:50
Thierry Parent26-Jun-13 21:50 
I don't want to give the sources but I can explain the principe.

It's not possible to open a port from android to the PC.
The opposite is possible. You can open a connection from the pc to android.

The first step is to create a single bydirectional tunnel between the pc and android.
To do it, you must tell to ADB to allow the communication.
The command is the folowing : ADB forward tcp:xxx tcp:yyy
So the windows app can open a <local> commnication on port xxx.
An android server must be listenning on <server> port yyy.
Both ports can be same number, like 9000 .
You can start the android server using "ADB shell am start xxx" command.
Pc can send commands to android, and android can send commands to pc

To forward the port android 8080 to Pc port 8085 (or same number) :

Second step : create a server socket for EACH port you want to forward.
When an application open a connection to this port, you must create a message "connection opened on port 8080" and send it to the pc using the tunnel. The pc will try to open a connection on localhost:8085

You have to handle a lot a message :

- PC to android : start server listening on TCP port 8080
- Android to PC : connection id 100 opened on port 8080
- PC to android : connection id 100 ok
- PC to android : connection error for id 100
- PC to android : connection time out id 100
- Android to PC : block of bytes for connection id 100
- PC to android : block of bytes for connection id 100
- Android to PC : connection closed for id 100
- PC to android : connection closed for id 100

This is not the full list of message.
You can have a lot of connections on the same port. So you must need to a connection ID
This is a VERY VERY long development process. Considere using UML for use case and message flow.


But, if you just want to open a single port (no forwarding) from pc to android,
just the "ADB forward" and start android server is needed.
GeneralRe: Want to understand. Pin
Никита Чехомов27-Jun-13 23:08
Никита Чехомов27-Jun-13 23:08 
QuestionNot able to use Android Usb Port Forwarding Pin
Prateek Kumar12-Jun-13 21:10
Prateek Kumar12-Jun-13 21:10 
Questioni did the process in my galaxy mini s5570 Pin
Advait Trivedi12-Jun-13 19:15
Advait Trivedi12-Jun-13 19:15 
Questiondefualt gateway Pin
Ashish Mittal3-Jun-13 2:23
Ashish Mittal3-Jun-13 2:23 
QuestionSamsung S3 (not rooted), it worked for all apps! (Firefox, Whatsapp, facebook...) Pin
Calories3329-Apr-13 4:15
professionalCalories3329-Apr-13 4:15 
AnswerRe: Samsung S3 (not rooted), it worked! Pin
Kevin Jeremy8-May-13 0:18
Kevin Jeremy8-May-13 0:18 
GeneralRe: Samsung S3 (not rooted), it worked! Pin
Calories338-May-13 20:09
professionalCalories338-May-13 20:09 
GeneralRe: Samsung S3 (not rooted), it worked! Pin
Kevin Jeremy11-May-13 0:47
Kevin Jeremy11-May-13 0:47 
GeneralRe: Samsung S3 (not rooted), it worked! Pin
Thierry Parent11-May-13 3:20
Thierry Parent11-May-13 3:20 
GeneralRe: Samsung S3 (not rooted), it worked! Pin
Kevin Jeremy11-May-13 23:53
Kevin Jeremy11-May-13 23:53 
GeneralRe: Samsung S3 (not rooted), it worked! Pin
Calories3315-May-13 19:31
professionalCalories3315-May-13 19:31 
GeneralRe: Samsung S3 (not rooted), it worked! Pin
Kevin Jeremy19-May-13 21:10
Kevin Jeremy19-May-13 21:10 
Questionnot connecting Pin
Nitin Soneji26-Mar-13 8:15
Nitin Soneji26-Mar-13 8:15 
Questionreach upto step4 but? Pin
gauravmay25-Mar-13 0:45
gauravmay25-Mar-13 0:45 
QuestionHelp Pin
popke9-Mar-13 7:35
popke9-Mar-13 7:35 
Questionplease help Pin
sja0516-Feb-13 19:26
sja0516-Feb-13 19:26 
QuestionSource Pin
eojjoe7-Feb-13 6:16
eojjoe7-Feb-13 6:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.