How to generate random IP with groovy : I can generate a string, but can't figure out a fast way to IP. org.apache.commons.lang.RandomStringUtils.random
Asked
Active
Viewed 554 times
1
-
Please refer to [this guide](https://stackoverflow.com/help/asking) to get the most out of StackOverflow. – Paul Hodges Dec 07 '17 at 14:37
-
Please read: https://stackoverflow.com/help/how-to-ask . You should provide us some code (stackoverflow isn't a service for developing your applications). – rweisse Dec 07 '17 at 14:37
1 Answers
2
If you just need random IP addresses, why not just something simple like:
def random = new Random()
(0..3).collect { random.nextInt(255) }.join('.')
You will end up with something like:
10.222.40.74

cjstehno
- 13,468
- 4
- 44
- 56