Skip to content

Commit

Permalink
增加端口自识别的安全处理
Browse files Browse the repository at this point in the history
  • Loading branch information
zaaksam committed Aug 23, 2017
1 parent fa15304 commit c4cf62e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions go/config/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ type appConf struct {

//newPort 查找可用端口
func newPort(ip string) int {
i := 0
for {
if i > 10 {
return 8080
}

r := rand.New(rand.NewSource(time.Now().UnixNano()))
port := r.Intn(60000)
if port <= 0 {
Expand All @@ -81,6 +86,7 @@ func newPort(ip string) int {
return port
}

i++
continue
}
conn.Close()
Expand Down

0 comments on commit c4cf62e

Please sign in to comment.