Skip to content

Commit 9918de8

Browse files
Merge pull request #13 from shadowy-pycoder/interfaces
added support for binding to network interfaces
2 parents b9e0f21 + f780ebf commit 9918de8

File tree

8 files changed

+179
-128
lines changed

8 files changed

+179
-128
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ You can download the binary for your platform from [Releases](https://github.com
101101
Example:
102102

103103
```shell
104-
HPTS_RELEASE=v1.9.2; wget -v https://github.com/shadowy-pycoder/go-http-proxy-to-socks/releases/download/$HPTS_RELEASE/gohpts-$HPTS_RELEASE-linux-amd64.tar.gz -O gohpts && tar xvzf gohpts && mv -f gohpts-$HPTS_RELEASE-linux-amd64 gohpts && ./gohpts -h
104+
GOHPTS_RELEASE=v1.9.3; wget -v https://github.com/shadowy-pycoder/go-http-proxy-to-socks/releases/download/$GOHPTS_RELEASE/gohpts-$GOHPTS_RELEASE-linux-amd64.tar.gz -O gohpts && tar xvzf gohpts && mv -f gohpts-$GOHPTS_RELEASE-linux-amd64 gohpts && ./gohpts -h
105105
```
106106

107107
Alternatively, you can install it using `go install` command (requires Go [1.24](https://go.dev/doc/install) or later):
@@ -142,15 +142,17 @@ Options:
142142
-h Show this help message and exit
143143
-v Show version and build information
144144
-D Run as a daemon (provide -logfile to see logs)
145+
-I Display list of network interfaces and exit
145146

146147
Proxy:
147-
-l Address of HTTP proxy server (default "127.0.0.1:8080")
148-
-s Address of SOCKS5 proxy server (default "127.0.0.1:1080")
148+
-l Address of HTTP proxy server (Default: "127.0.0.1:8080")
149+
-s Address of SOCKS5 proxy server (Default: "127.0.0.1:1080")
149150
-c Path to certificate PEM encoded file
150151
-k Path to private key PEM encoded file
151152
-U User for HTTP proxy (basic auth). This flag invokes prompt for password (not echoed to terminal)
152153
-u User for SOCKS5 proxy authentication. This flag invokes prompt for password (not echoed to terminal)
153-
-f Path to server configuration file in YAML format (overrides other proxy flags)
154+
-i Bind proxy to specific network interface (either by interface name or index)
155+
-f Path to server configuration file in YAML format (overrides proxy flags above)
154156

155157
Logs:
156158
-d Show logs in DEBUG mode
@@ -279,7 +281,8 @@ proxy_list:
279281
- address: 127.0.0.1:1081
280282
- address: :1082 # empty host means localhost
281283
server:
282-
address: 127.0.0.1:8080 # the only required field in this section
284+
address: 127.0.0.1:8080 # the only required field in this section (ignored when -T flag specified)
285+
interface: "eth0" # if specified, overrides server address
283286
# these are for adding basic authentication
284287
username: username
285288
password: password

cmd/gohpts/cli.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"slices"
99

1010
gohpts "github.com/shadowy-pycoder/go-http-proxy-to-socks"
11+
"github.com/shadowy-pycoder/mshark/network"
1112
"golang.org/x/term"
1213
)
1314

@@ -33,15 +34,17 @@ Options:
3334
-h Show this help message and exit
3435
-v Show version and build information
3536
-D Run as a daemon (provide -logfile to see logs)
37+
-I Display list of network interfaces and exit
3638
3739
Proxy:
38-
-l Address of HTTP proxy server (default "127.0.0.1:8080")
39-
-s Address of SOCKS5 proxy server (default "127.0.0.1:1080")
40+
-l Address of HTTP proxy server (Default: "127.0.0.1:8080")
41+
-s Address of SOCKS5 proxy server (Default: "127.0.0.1:1080")
4042
-c Path to certificate PEM encoded file
4143
-k Path to private key PEM encoded file
4244
-U User for HTTP proxy (basic auth). This flag invokes prompt for password (not echoed to terminal)
4345
-u User for SOCKS5 proxy authentication. This flag invokes prompt for password (not echoed to terminal)
44-
-f Path to server configuration file in YAML format (overrides other proxy flags)
46+
-i Bind proxy to specific network interface (either by interface name or index)
47+
-f Path to server configuration file in YAML format (overrides proxy flags above)
4548
4649
Logs:
4750
-d Show logs in DEBUG mode
@@ -90,6 +93,15 @@ func root(args []string) error {
9093
"",
9194
"Path to server configuration file in YAML format (overrides other proxy flags)",
9295
)
96+
flags.StringVar(&conf.Interface, "i", "", "Bind proxy to specific network interface")
97+
flags.BoolFunc("I", "Display list of network interfaces and exit", func(flagValue string) error {
98+
if err := network.DisplayInterfaces(); err != nil {
99+
fmt.Fprintf(os.Stderr, "%s: %v\n", app, err)
100+
os.Exit(2)
101+
}
102+
os.Exit(0)
103+
return nil
104+
})
93105
daemon := flags.Bool("D", false, "Run as a daemon (provide -logfile to see logs)")
94106
if runtime.GOOS == tproxyOS {
95107
flags.StringVar(&conf.TProxy, "t", "", "Address of transparent proxy server (it starts along with HTTP proxy server)")
@@ -157,7 +169,7 @@ func root(args []string) error {
157169
if seen["T"] {
158170
for _, da := range []string{"U", "c", "k", "l"} {
159171
if seen[da] {
160-
return fmt.Errorf("-T flag only works with -s, -u, -f, -M, -d, -D, -logfile, -sniff, -snifflog and -j flags")
172+
return fmt.Errorf("-T flag does not work with -U, -c, -k, -l flags")
161173
}
162174
}
163175
if !seen["M"] {
@@ -180,12 +192,9 @@ func root(args []string) error {
180192
}
181193
}
182194
if seen["f"] {
183-
for _, da := range []string{"s", "u", "U", "c", "k", "l"} {
195+
for _, da := range []string{"s", "u", "U", "c", "k", "l", "i"} {
184196
if seen[da] {
185-
if runtime.GOOS == tproxyOS {
186-
return fmt.Errorf("-f flag only works with -t, -T, -M, -d, -D, -logfile, -sniff, -snifflog and -j flags")
187-
}
188-
return fmt.Errorf("-f flag only works with -d, -D, -logfile, -sniff, -snifflog and -j flags")
197+
return fmt.Errorf("-f flag does not work with other proxy flags specified")
189198
}
190199
}
191200
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/google/uuid v1.6.0
88
github.com/rs/zerolog v1.34.0
99
github.com/shadowy-pycoder/colors v0.0.1
10-
github.com/shadowy-pycoder/mshark v0.0.8
10+
github.com/shadowy-pycoder/mshark v0.0.9
1111
golang.org/x/net v0.40.0
1212
golang.org/x/sys v0.33.0
1313
golang.org/x/term v0.32.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
3030
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
3131
github.com/shadowy-pycoder/colors v0.0.1 h1:weCj/YIOupqy4BSP8KuVzr20fC+cuAv/tArz7bhhkP4=
3232
github.com/shadowy-pycoder/colors v0.0.1/go.mod h1:lkrJS1PY2oVigNLTT6pkbF7B/v0YcU2LD5PZnss1Q4U=
33-
github.com/shadowy-pycoder/mshark v0.0.8 h1:7kuVgX9Qp4Q9nGl9Gi7UOaNFUnOF0I2Vpfmc4X3GLug=
34-
github.com/shadowy-pycoder/mshark v0.0.8/go.mod h1:FqbHFdsx0zMnrZZH0+oPzaFcleP4O+tUWv8i5gxo87k=
33+
github.com/shadowy-pycoder/mshark v0.0.9 h1:mMHmkqUpkSlkt74DaSkNjhvO0nJ0AxZiYPH6QbllB9A=
34+
github.com/shadowy-pycoder/mshark v0.0.9/go.mod h1:FqbHFdsx0zMnrZZH0+oPzaFcleP4O+tUWv8i5gxo87k=
3535
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
3636
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
3737
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=

0 commit comments

Comments
 (0)