Ping Random IPs using a tcsh script..
I want a script so as to be able to ping 255 ip addresses but I want to produce these addresses dynamically (or even random)
any help? the ip should be 192.168.1.xxx |
are they all on the same subnet eg is it 192.168.2.x where x varies between 1 and 254 or is it just 255 totally random addresses, also does it have to do each address once or can it repeat the same address?
|
They all are on the same subnet eg is it 192.168.2.x where x varies between 1 and 254
it would be better if it won't repeat the same address. thanks for the quick reply.. |
i cant see how to do it in a shell script without repeating the same address, it would be much easier to do from a c program.
|
ok never mind repeating..
|
this basically spews out 254 random ip addresses you just have to modify it to ping them.
#!/bin/bash COUNTER=254 RANDMAX=3600 RANDOM=$(( $(date '+%S') * $(date '+%M') )) while [ $COUNTER -gt 0 ]; do RANDOM=$(( $RANDOM * 137 + 258 % RANDMAX )) echo 192.168.2.$(( $RANDOM % 255 )) COUNTER=$(( $COUNTER-1 )) done; i dont know how good my random number generation is but it seems to work. <edit>just realised it can produce 192.168.2.0 but im sure you can modify it to your needs |
Quote:
But it will produce much less random numbers when you use another name for "RANDOM" ! Bash has it's own random generator, and it uses the RANDOM variable for this. Quote:
echo 192.168.2.$(( $RANDOM % 255 )) its not your number-fiddling producing the randomness, but bash's own random generator ! |
wow, i didnt know that. guess i should have looked at the man page, and i thought my number fiddling was doing really well. never mind.
|
All times are GMT -5. The time now is 02:24 AM. |