File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,44 @@ func RandIPv4() net.IP {
152152 )
153153}
154154
155+ // RandIPv4Private Generates a random private IPv4 address.
156+ func RandIPv4Private () net.IP {
157+ n , _ := rand .Int (rand .Reader , big .NewInt (3 ))
158+ switch n .Int64 () {
159+ case 0 :
160+ return net .IPv4 (
161+ 10 ,
162+ byte (RandIntRange (1 , 256 )),
163+ byte (RandIntRange (1 , 256 )),
164+ byte (RandIntRange (1 , 256 )),
165+ )
166+ case 1 :
167+ return net .IPv4 (
168+ 172 ,
169+ byte (RandIntRange (16 , 32 )),
170+ byte (RandIntRange (1 , 256 )),
171+ byte (RandIntRange (1 , 256 )),
172+ )
173+ default :
174+ return net .IPv4 (
175+ 192 ,
176+ 168 ,
177+ byte (RandIntRange (1 , 256 )),
178+ byte (RandIntRange (1 , 256 )),
179+ )
180+ }
181+ }
182+
183+ // RandomIPv4Loopback generates IPv4 Loopback address
184+ func RandIPv4Loopback () net.IP {
185+ return net .IPv4 (
186+ 127 ,
187+ 0 ,
188+ 0 ,
189+ 1 ,
190+ )
191+ }
192+
155193// RandIPv6 generates a random IPv6 address.
156194func RandIPv6 () net.IP {
157195 ip := make (net.IP , net .IPv6len )
You can’t perform that action at this time.
0 commit comments