re situations where we can benefit from generating arbitrary IP addresses in bash. In this case, the first octet situations where There are situations where we can benefit from generating arbitrary IP addresses in bash. In this case, the first octet situations where we can benefit from generating arbitrary IP addresses in bash. In this case, the first octet in bash. In this case, the first octet situations where we can benefit from generating arbitrary IP addresses in bash. In this case (224.*.*.* / 10.*.*.* / 127.*.*.* / 0.*.*.* / 192.168.*.* / 172.16.*.* / 172.31.*.*) is not generated. Of course, the script can be adapted to your needs.
1 |
$ cat random_ip.sh |
1 2 3 4 5 6 7 8 9 |
#!/bin/bash while true; do set $(dd if=/dev/urandom bs=4 count=1 2>/dev/null | od -An -tu1) if [ $1 -lt 224 ] && [ $1 -ne 10 ] && [ $1 -ne 127 ] && [ $1 -ne 0 ] && { [ $1 -ne 192 ] || [ $2 -ne 168 ]; } && { [ $1 -ne 172 ] || [ $2 -lt 16 ] || [ $2 -gt 31 ]; } then ip_address=$1.$2.$3.$4 echo $ip_address fi done |
You can also download this script:
1 |
$ wget soban.pl/bash/random_ip.sh |
You should give the script the ability to run it:
1 |
$ chmod +x random_ip.sh |
Here’s the effect when you run it: