utils.go 486 B

123456789101112131415161718192021222324252627282930
  1. package tool
  2. import (
  3. "github.com/cnlh/nps/lib/common"
  4. "github.com/cnlh/nps/vender/github.com/astaxie/beego"
  5. )
  6. var ports []int
  7. func init() {
  8. p := beego.AppConfig.String("allowPorts")
  9. ports = common.GetPorts(p)
  10. }
  11. func TestServerPort(p int, m string) (b bool) {
  12. if p > 65535 || p < 0 {
  13. return false
  14. }
  15. if len(ports) != 0 {
  16. if !common.InIntArr(ports, p) {
  17. return false
  18. }
  19. }
  20. if m == "udp" {
  21. b = common.TestUdpPort(p)
  22. } else {
  23. b = common.TestTcpPort(p)
  24. }
  25. return
  26. }