求一个脚本:自动telnet多个设备(192.168.1.1-10),执行show run命令,并将返回的信息输出到指定文件
简单写一个,根据自己情况改吧 #!/bin/bashfor i in `seq 1 10`doecho "=============IP: 192.168.1.$i=============="(sleep 3;echo admin;sleep 3;echo admin;sleep 3;echo "terminal length 0";sleep 3;echo "show run";sleep 3;exit;)|telnet 192.168.1.$i >> result.`date +%Y%m%d.log 2>&1echo "===========================================" done

如何用shell脚本实现自动telnet-snowtty-ChinaUnix博客
Shell脚本自动Telnet并执行远端机器的脚本 简单使用状况[plain]#!/bin/sh(sleep 10;echo "username";sleep 10;echo "password";sleep 10;echo "pwd";sleep 50;#echo exit)|telnet $ip这里只是连接到远端机器,查看一下当前所在的目录。username/password 是telnet 到远端机器的用户名,密码sleep 是一个等待时间,根据具体的机器状况或是执行命令的需要的时间来设置。带变量使用 [plain]

python telnet 脚本怎么 ping ip ?
(1)安装telnetd(即telnet-server):apt-get install telnetd (2)安装xinetd(telnet-server的运行需要由xinetd来管理):apt-get install xinetd(3)配置telnet文件:vi /etc/xinetd.d/telnet(4)开启xinetd:service xinetd start#!/usr/bin/env python#coding=utf-8import sysimport telnetlibimport osimport timeenter='n'filehead="D:\file\"filetail=".txt"def getfile(filename):f=open(filename,'w+')while(1):ret=tn.read_until('#',1)f.write(ret)if '#' in ret:breakelse:for i in range(10):tn.write(' ')time.sleep(0.1)f.close()#check the file is existd or notdef get(string):tn.write(string+enter)filename=filehead+string.replace(' ','-')+filetailgetfile(filename)print string+' information is in '+filenameprint 'Router#'def login():password=sys.argv[2]#get ordinary certificatetn.read_until("Password: ",1)tn.write(password + enter)#want to get admin certificatetn.read_until("Router>",1)tn.write('en'+enter)#get admin certificatetn.read_until("Password: ",1)tn.write(password + enter)#enter routeprint tn.read_until("Router#",1)def options():showstring=["show version","show arp","show run","show running-config","show startup-config","show ip interface brief","show ip route"]while 1:string=raw_input()string=string.lower()if string=='exit':tn.write('exit'+enter)print 'exit success'breakelif string in showstring:get(string)else:print 'wrong input'print 'please enter an order'if __name__ == "__main__":Host=sys.argv[1]tn=telnetlib.Telnet(Host)login()options() 使用方法是:python *.py ip号 登陆密码

如何用shell脚本实现自动telnet
很多人认为telnet象passwd和su一样,无法通过管道和输入转向使其自动工作,但实际上telnet是支持输入转向的.虽然,严格的说,shell脚本无法使telnet进入交互状态,但它确实可你使你进入远程系统并运行你希望的命令后退出.这远比用rsh(remsh,rcmd)更令人放心, 使用如下的脚本可以达到你的要求:(sleep 1;echo user;sleep 1; echo passwd;echo yourcmd ;sleep 1)|telnet remotehost其中user,passwd,yourcmd,remotehost分别更换成你的用户名,用户口令,你想要运行的命令,远程机器名或IP便可以了. 如果要想使用脚本进入交互状态,可以使用expect.如果你要通过telnet某个IP的端口来得到部分数据,则可以用以下命令(sleep 5;) | telnet IP PORT 这样就可以在telnet后将PORT在5秒内输出的数据打印到屏幕上,然后自动退出EG:tempValue="KEY"str4=`(sleep 1;echo AA;sleep 1; echo 123; sleep 1; echo tail -f /aa/log/a.log;sleep 1) | telnet ${IP} | grep ${tempValue}`num4=`echo ${#str4}`if [ ${num4} -eq 0 ];thenecho "==::在a.log文件中没有找到关键字KEY,请检查!"sheet4="@NULL"elseecho "==::在a.log文件有找到关键字KEY!"sheet4="@OK" fi

Linux如何通过脚本,不停地telnet一个IP,记录telnet成功的时间并输出?
Telnet本身对另一台服务器检查时,容易退不出来。使用Nmap比较合适,然后写个如下脚本,变更IP及相应的端口及Sleep的时间就可以达到目标。如下参考:#!/bin/bash#Purpose:check ip portPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATH# Check if user is rootif [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script" exit 1fiCur_Dir="$(cd -P "$(dirname "${BASHSOURCE[0]}")" && pwd)"Cur_Time="$(date +%Y%m%d%H%M%S)"Dest_Ip=172.16.3.19Dest_Port=22if [ ! -f /usr/bin/nmap ];thenyum -y install nmapelse:fifunction Check_Port(){Port_State=$(nmap -P0 -sS -p${Dest_Port} ${Dest_Ip}|awk '/STATE/{getline v;print v}'|awk '{print $2}')if [ X${Port_State}==X'open' ];thenecho "${Dest_Ip} ${Dest_Port} is open" >>${Cur_Dir}/status.txtecho "${Cur_Time}" >>${Cur_Dir}/status.txtelseecho "${Dest_Ip} ${Dest_Port} is failure" >>${Cur_Dir}/status.txtecho "${Cur_Time}" >>${Cur_Dir}/status.txtfi}while true;doCheck_Portsleep 3done
不需要使用脚本吧,直接telnet ip 端口 -a就行了

本文由 在线网速测试 整理编辑,转载请注明出处。