Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. Class Starting IPAddress Ending IP Address # of Hosts
  2. A 10.0.0.0 10.255.255.255 16,777,216
  3. B 172.16.0.0 172.31.255.255 1,048,576
  4. C 192.168.0.0 192.168.255.255 65,536
  5. Link-local-u 169.254.0.0 169.254.255.255 65,536
  6. Link-local-m 224.0.0.0 224.0.0.255 256
  7. Local 127.0.0.0 127.255.255.255 16777216
  8.  
  9. func IsPublicIP(IP net.IP) bool {
  10. if IP.IsLoopback() || IP.IsLinkLocalMulticast() || IP.IsLinkLocalUnicast() {
  11. return false
  12. }
  13. if ip4 := IP.To4(); ip4 != nil {
  14. switch {
  15. case ip4[0] == 10:
  16. return false
  17. case ip4[0] == 172 && ip4[1] >= 16 && ip4[1] <= 31:
  18. return false
  19. case ip4[0] == 192 && ip4[1] == 168:
  20. return false
  21. default:
  22. return true
  23. }
  24. }
  25. return false
  26. }
  27.  
  28. //function to get the public ip address
  29. func GetOutboundIP() string {
  30. conn, err := net.Dial("udp", "8.8.8.8:80")
  31. HandleError("net.Dial: ",err)
  32. defer conn.Close()
  33. localAddr := conn.LocalAddr().String()
  34. idx := strings.LastIndex(localAddr, ":")
  35. return localAddr[0:idx]
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement