Sunday 10 August 2014

IP Telnet

This script is your basic Telnet script.
In order to use this script you must create a text file called 'ip' and fill it with the ip(s) you wish to connect to.

The script loops through the list of IP addresses in the file and ping's them. Once it has a ping it starts Telnet and issues commands between sleeps. Just fill out the relevant information (username, password and required commands). The script loops through the ip.txt file and ping's the address, if the ping is successful it will go on to do the telnet, if not it will skip that IP and move on to the next.
#!/bin/bash
while read line
do
# -c 1 means ping only once
# -w means time-out, so if nothing is received within 5 seconds then it's a fail
if ! ping -c 1 -w 5 $line &/dev/null ;
then
echo "Failed to connect to $line"
else
echo "Connected to $line!"
username=user
passwd=password
port=23
cmd1=""
cmd2=""
cmd3=""
( echo open ${line} ${port}
sleep 2
echo ${username}
sleep 2
echo ${passwd}
sleep 2
echo ${cmd1}
sleep 2
echo ${cmd2}
sleep 3
echo exit ) | telnet
fi
done < ip.txt

No comments:

Post a Comment