2019-02-12 19:54:00 +00:00
|
|
|
package tool
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cnlh/nps/lib/common"
|
2019-02-16 12:43:26 +00:00
|
|
|
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
|
2019-02-12 19:54:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var ports []int
|
|
|
|
|
|
|
|
func init() {
|
2019-03-05 01:23:18 +00:00
|
|
|
p := beego.AppConfig.String("allow_ports")
|
2019-02-15 14:59:28 +00:00
|
|
|
ports = common.GetPorts(p)
|
2019-02-12 19:54:00 +00:00
|
|
|
}
|
2019-02-15 14:59:28 +00:00
|
|
|
|
2019-02-12 19:54:00 +00:00
|
|
|
func TestServerPort(p int, m string) (b bool) {
|
2019-03-01 09:23:14 +00:00
|
|
|
if p > 65535 || p < 0 {
|
2019-02-23 15:29:48 +00:00
|
|
|
return false
|
|
|
|
}
|
2019-02-12 19:54:00 +00:00
|
|
|
if len(ports) != 0 {
|
|
|
|
if !common.InIntArr(ports, p) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2019-03-01 09:23:14 +00:00
|
|
|
if m == "udp" {
|
2019-02-12 19:54:00 +00:00
|
|
|
b = common.TestUdpPort(p)
|
|
|
|
} else {
|
|
|
|
b = common.TestTcpPort(p)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|