Milon
February 2, 2016, 12:58pm
1
Hi,
I need to write a bash script that will random choose and login into these below ip addresses.
192.168.116.130
192.168.116.131
192.168.116.132
192.168.116.133
I'm new into scripting and I need to enhance my logic. Below is what i did
#!/bin/bash
p=$1
localip=$2
port=$3
localport=$4
if [ "$#" -ne 4 ]; then
exit 1
fi
case "$2" in
1) return_string="Milon1, 192.168.116.130, 22"
echo "$return_string"
;;
2) return_string="Milon2, 192.168.116.131, 22"
echo "$return_string"
;;
3) return_string="Milon3, 192.168.116.132, 22"
echo "$return_string"
;;
*) return_string="Milon4, 192.168.116.133, 22"
echo "$return_string"
;;
esac
RudiC
February 2, 2016, 2:36pm
2
Please use code tags as required by forum rules!
So - the random value would be supplied as $2 between 1 and 4?
---------- Post updated at 20:36 ---------- Previous update was at 19:05 ----------
Just some thoughts as a starting point:
IP=(192.168.116.13{0..3})
for ((i=1; i<=8; i++)); do R=$((RANDOM%4)); echo "Milon$R, ${IP[$R]}, 22"; done
Milon2, 192.168.116.132, 22
Milon3, 192.168.116.133, 22
Milon2, 192.168.116.132, 22
Milon0, 192.168.116.130, 22
Milon1, 192.168.116.131, 22
Milon1, 192.168.116.131, 22
Milon3, 192.168.116.133, 22
Milon1, 192.168.116.131, 22
Milon
February 2, 2016, 3:09pm
3
The problem is I'm very new in bash
script.
Will the below script produce the below results?
#!/bin/bash
p=$1
localip=$2
port=$3
localport=$4
if [ "$#" -ne 4 ]; then
exit 1
fi
IP=(192.168.116.13{0..3})
for ((i=1; i<=8; i++)); do R=$((RANDOM%4)); echo "Milon$R, ${IP[$R]}, 22"; done
Results:
Milon2, 192.168.116.132, 22
Milon3, 192.168.116.133, 22
Milon2, 192.168.116.132, 22
Milon0, 192.168.116.130, 22
Milon1, 192.168.116.131, 22
Milon1, 192.168.116.131, 22
Milon3, 192.168.116.133, 22
Milon1, 192.168.116.131, 22
RudiC
February 3, 2016, 4:05am
4
Why don't you run it so you can see?
And, I guess (as you don't explicitly explain) that you want script parameters to hold IP addresses and ports, and that the "22" is a port (indicating you want to login via ssh
). But, again, there's no indication about what is what.
Why don't you step back and write a detailed specification?
Milon
February 3, 2016, 9:51am
5
I want the system to randomly pick a honeypot sensor for a user to login.
ip=$1
localip=$2
port=$3
localport=$4
if [ "$#" -ne 4 ]; then
$username = $5
$password = $6
fi
IP=(192.168.116.13{0..3})
for ((i=1; i<=8; i++)); do R=$((RANDOM%4)); echo "Milon$R, ${IP[$R]}, 22"; done
return_string="Sensor_Name, Honey_IP, Honey_Port"
if [ "$#" -ne 4 ]; then
return_string="$return_string, $username, $password"
fi
echo "$return_string"