specify server listen address

This commit is contained in:
xmapst 2022-05-25 15:30:36 +08:00
parent bbd409061c
commit db205716f8
3 changed files with 8 additions and 5 deletions

View File

@ -35,6 +35,7 @@ sudo ./UnblockNeteaseMusic
```shell
./UnblockNeteaseMusic -h
-a specify server listen address,such as : "0.0.0.0"
-b force the best music quality
-c string
specify server cert,such as : "server.crt" (default "./server.crt")

View File

@ -8,13 +8,14 @@ import (
"os"
"path/filepath"
"strings"
"github.com/cnsilvan/UnblockNeteaseMusic/common"
"github.com/cnsilvan/UnblockNeteaseMusic/utils"
"github.com/cnsilvan/UnblockNeteaseMusic/version"
)
var (
Addr = flag.String("a", "0.0.0.0", "specify server listen address,such as : \"0.0.0.0\"")
Port = flag.Int("p", 80, "specify server port,such as : \"80\"")
TLSPort = flag.Int("sp", 443, "specify server tls port,such as : \"443\"")
Source = flag.String("o", "kuwo", "specify server source,such as : \"kuwo\"")
@ -60,7 +61,7 @@ func ValidParams() bool {
for _, source := range sources {
common.Source = append(common.Source, source)
}
currentPath, err := utils.GetCurrentPath()
if err != nil {
log.Println(err)

View File

@ -3,6 +3,7 @@ package proxy
import (
"bytes"
"crypto/tls"
"fmt"
"io"
"log"
"net"
@ -26,7 +27,7 @@ var localhost = map[string]int{}
func InitProxy() {
log.Println("-------------------Init Proxy-------------------")
address := "0.0.0.0:"
// address := "0.0.0.0:"
addrs, err := net.InterfaceAddrs()
if err != nil {
panic(err)
@ -47,8 +48,8 @@ func InitProxy() {
}
log.Println("Http Proxy:")
log.Println(strings.Join(localhostKey, " , "))
go startTlsServer(address+strconv.Itoa(*config.TLSPort), *config.CertFile, *config.KeyFile, &HttpHandler{})
go startServer(address+strconv.Itoa(*config.Port), &HttpHandler{})
go startTlsServer(fmt.Sprintf("%s:%d", *config.Addr, *config.TLSPort), *config.CertFile, *config.KeyFile, &HttpHandler{})
go startServer(fmt.Sprintf("%s:%d", *config.Addr, *config.Port), &HttpHandler{})
}
func (h *HttpHandler) ServeHTTP(resp http.ResponseWriter, request *http.Request) {
defer func() {