Chinaunix首页 | 论坛 | 博客
  • 博客访问: 278015
  • 博文数量: 65
  • 博客积分: 3091
  • 博客等级: 中校
  • 技术积分: 705
  • 用 户 组: 普通用户
  • 注册时间: 2005-01-25 09:44
文章存档

2013年(2)

2012年(11)

2011年(12)

2010年(13)

2009年(15)

2008年(12)

分类: Python/Ruby

2012-01-19 17:44:44

################################
## autotelnet.sh
################################
#!/bin/bash

OS_TYPE=`uname`
HOSTNAME=`hostname`
if [ -n "$1" ]; then
    SERVNAME="$1"
else
    SERVNAME=10.21.32.43
fi

if [ -z "$DISPLAY" ]; then
    DISPLAY="$HOSTNAME:0.0"
fi

#
xhost +
#

#LOOKUP_PID="ps -ef | grep bash.*ut_gui.sh | grep -v grep | awk '{print $2}'"
#if [ -n "$LOOKUP_PID" ]; then
#    echo "PID $LOOKUP_PID of ut_gui.sh is active"
#else
#    LOOKUP_PID="ps -ef | grep telnet.*$HOSTNAME | grep -v grep | awk '{print $2}'"
#    while [ -n "$LOOKUP_PID" ]
#    do
#        kill -9 $LOOKUP_PID
#        sleep 1
#        LOOKUP_PID="ps -ef | grep bash.*ut_gui.sh | grep -v grep | awk '{print $2}'"
#    done
#fi

#
## telnet destination host
#

### Automating Telnet
echo $OS_TYPE $HOSTNAME
echo "telnet $SERVNAME"
(sleep 1
echo "usrname"
sleep 1
echo "usrpass"
sleep 1
##echo "whoami"
##sleep 1
cmdstr=`which xcalc`
echo "bash -i -c $cmdstr $DISPLAY"
while true
do
    read cmdstr
    if [ "$cmdstr" = "exit" ]; then
        echo $cmdstr; exit
    else
        echo $cmdstr
    fi
done
)|telnet $SERVNAME

################################
#### Reference ####
################################
##!/bin/bash
#
#usrtty=`tty`                 #取得当前使用的tty值
#usrtty=`basename $usrtty`    #去掉tty的绝对路径
#usrname=`whoami`             #取得当前执行程序的用户名
#dest_ip="10.21.32.43"        #目标主机地址
#if [ -n "$1" ]; then
#    dest_ip="$1"
#fi
#inp1="usrname^M"             #主机的用户名,注意^M是UNIX下的回车换行符号(\r\n),必须在UNIX终端窗口下使用正确的方法输入!
#                             #方法:按下ctrl v键输入后,再按下ctrl shift m键,完成后全部放开
#inp2="usrpass^M"             #主机的密码,同上需要输入^M
#inp3="ls^M"                  #登录后执行的命令,可为空或用ls之类的命令代替,同上需要输入^M
#inp4="pwd^M"                 #其它命令,同上
#
##--------------------------
#inputfile=in                 #管道所用的输入文件(可用其它文件名)
#outputfile=out.log           #管道所用的输出文件
#rm -rf $inputfile
#rm -rf $outputfile
#mknod $inputfile p
#touch $outputfile
#
##file description 8 for stdin and 9 for stdout 使用8作为管道输入文件描述符,输出使用9
#exec 8<>$inputfile
#exec 9<>$outputfile
#
#telnet $dest_ip <&8 >&9 &
#
#sleep 1; echo $inp1 >> $inputfile      #将用户名和密码字符串输送到管道文件中
#sleep 1; echo $inp2 >> $inputfile
#sleep 1; echo $inp3 >> $inputfile      #将命令行字符串输送到管道文件中
#sleep 1; echo $inp4 >> $inputfile
#
#tail -f $outputfile &        #将输出的内容以接续方式显示出来
#
#while true                   #至此已经登录进入目标主机了,可以输入任何命令,内容被转递到输入管道中
#do
#  read str
#  if [[ $str = "quit" || $str = "exit" ]]; then
#    echo $str >> $inputfile ; exit
#  else
#    echo $str >> $inputfile
#  fi
#done
#
##退出时自动杀掉相关进程
#ps -ef | grep telnet | grep -v grep | grep -v telnetd | grep $usrtty | grep $usrname | awk '{print "kill -9", $2}' | sh
#ps -ef | grep "tail.*$outputfile" | grep -v grep | grep $usrtty | grep $usrname | awk '{print "kill -9", $2}' | sh
#

#!/bin/bash
[ -p tmp ] || { rm -f tmp;mkfifo tmp; }
exec 3<>tmp
telnet 127.0.0.1 <&3 &
sleep 1
(
    echo "pas"
    sleep 1
    #echo "pas"
    #sleep 1
    echo "xcalc"
    echo "exit"
) >& 3
wait $!
rm -f tmp

#!/usr/bin/bash
REMOTE_HOST=127.0.0.1
USER=pas
PASS=pas
(
        echo "${USER}"
        sleep 1
        echo "${PASS}"
        sleep 1
        #echo "xcalc; exit"  # or echo "exec xcalc"
        #cat                 # to maintain the pipe
        echo "nohup xcalc"
        sleep 1
        echo "exit"
) | telnet ${REMOTE_HOST}

阅读(2242) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~