You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
558 B

  1. package main
  2. import (
  3. "math/rand"
  4. "net"
  5. "strings"
  6. )
  7. func getIPPortFromConn(conn net.Conn) string {
  8. ip := getIPFromConn(conn)
  9. port := getPortFromConn(conn)
  10. return ip + ":" + port
  11. }
  12. func getIPFromConn(conn net.Conn) string {
  13. s := conn.RemoteAddr().String()
  14. s = strings.Split(s, ":")[0]
  15. s = strings.Trim(s, ":")
  16. return s
  17. }
  18. func getPortFromConn(conn net.Conn) string {
  19. s := conn.RemoteAddr().String()
  20. s = strings.Split(s, ":")[1]
  21. s = strings.Trim(s, ":")
  22. return s
  23. }
  24. func randInt(min int, max int) int {
  25. r := rand.Intn(max-min) + min
  26. return r
  27. }