github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/lib/others/sys/ipnet.go (about)

     1  package sys
     2  
     3  import (
     4  )
     5  
     6  
     7  // Discard any IP that may refer to a local network
     8  func ValidIp4(ip []byte) bool {
     9  	// local host
    10  	if ip[0]==0 || ip[0]==127 {
    11  		return false
    12  	}
    13  
    14  	// RFC1918
    15  	if ip[0]==10 || ip[0]==192 && ip[1]==168 || ip[0]==172 && ip[1]>=16 && ip[1]<=31 {
    16  		return false
    17  	}
    18  
    19  	//RFC3927
    20  	if ip[0]==169 && ip[1]==254 {
    21  		return false
    22  	}
    23  
    24  	return true
    25  }
    26  
    27  
    28  func IsIPBlocked(ip4 []byte) bool {
    29  	return false
    30  }