Skip to content

Commit 2d3c0e9

Browse files
committed
support share in local
1 parent aba82cf commit 2d3c0e9

File tree

3 files changed

+59
-10
lines changed

3 files changed

+59
-10
lines changed

README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
`fa` is a command line tool that wraps `adb` in order to extend it with extra features and commands that make working with Android easier.
66

7+
This project is still in developing, please be careful when use in production.
8+
79
## Features
810
- [x] show device selection when multi device connected
911
- [x] screenshot
@@ -132,18 +134,27 @@ $ adb shell /data/local/tmp/busybox ls
132134
Share local device
133135
134136
```bash
137+
# share in localnet
135138
$ fa share
136-
# here will print a address, eg: tcp://max.labstack.me:8000
139+
Connect with: adb connect 10.0.0.1:6174
140+
141+
# share to public ip
142+
$ fa share --tunnel
143+
______ __
144+
/_ __/_ _____ ___ ___ / /
145+
/ / / // / _ \/ _ \/ -_) /
146+
/_/ \_,_/_//_/_//_/\__/_/ v0.2.11
147+
148+
Expose local servers to internet securely
149+
https://labstack.com/docs/tunnel
150+
________________________________O/_______
151+
O\
152+
⇨ routing traffic from tcp://leo.labstack.me:10081
137153
```
138154
139-
In another machine use `adb connect`, for example the share addr is `max.labstack.me:8000`
155+
When use tunnel, you should use `adb connect leo.labstack.me:10081`
140156
141-
```bash
142-
$ adb connect max.labstack.me:8000
143-
device connected
144-
$ adb -s max.labstack.me:8000 shell pwd
145-
/
146-
```
157+
Then you can use adb to do anything just like device plugged in your computer.
147158
148159
### Pidcat (logcat)
149160
Current implementation is wrapper of [pidcat.py](https://github.com/JakeWharton/pidcat)

main.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"path/filepath"
1515
"regexp"
1616
"runtime"
17+
"strconv"
1718
"strings"
1819
"syscall"
1920
"time"
@@ -451,7 +452,18 @@ func main() {
451452
},
452453
{
453454
Name: "share",
454-
Usage: "share device as address for adb connect",
455+
Usage: "provides an USB device over TCP using a translating proxy",
456+
Flags: []cli.Flag{
457+
cli.BoolFlag{
458+
Name: "tunnel",
459+
Usage: "share device to public net, using labstack.me tunnel service",
460+
},
461+
cli.IntFlag{
462+
Name: "port",
463+
Usage: "listen port",
464+
Value: 6174,
465+
},
466+
},
455467
Action: func(ctx *cli.Context) error {
456468
serial, err := chooseOne()
457469
if err != nil {
@@ -460,10 +472,17 @@ func main() {
460472
client := adb.NewClient(fmt.Sprintf("%s:%d", defaultHost, defaultPort))
461473
device := client.DeviceWithSerial(serial)
462474

475+
if !ctx.Bool("tunnel") {
476+
adbd := adb.NewADBDaemon(device)
477+
fmt.Printf("Connect with: adb connect %s:%d\n", GetLocalIP(), ctx.Int("port"))
478+
return adbd.ListenAndServe(":" + strconv.Itoa(ctx.Int("port")))
479+
}
480+
481+
rand.Seed(time.Now().Unix())
463482
c := &tunnel.Configuration{
464483
Host: "labstack.me:22",
465484
RemoteHost: "0.0.0.0",
466-
RemotePort: 10000 + rand.Intn(1000),
485+
RemotePort: 10000 + rand.Intn(2000),
467486
Channel: make(chan int),
468487
InBoundConnectionHook: func(in net.Conn) error {
469488
log.Println("Accept new connection", in.RemoteAddr().String())

utils.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import "net"
4+
5+
func GetLocalIP() string {
6+
addrs, err := net.InterfaceAddrs()
7+
if err != nil {
8+
return "localhost"
9+
}
10+
for _, address := range addrs {
11+
// check the address type and if it is not a loopback the display it
12+
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
13+
if ipnet.IP.To4() != nil {
14+
return ipnet.IP.String()
15+
}
16+
}
17+
}
18+
return "localhost"
19+
}

0 commit comments

Comments
 (0)