本帖最后由 小熵 于 2012-9-11 09:36 编辑
呼叫 olala,呼叫pcbar,呼叫各位大神...
另外一类似问题
http://www.autoitx.com/forum.php ... mp;highlight=telnet
在论坛看了TCPsend来进行Telnet,按照一下代码进行之后,提示4个问号,并提示"Cannot connect2"
使用au3检测返回信息的是什么弄的?一部分吗?(If StringInStr($ack, "login:") >= 1 Then ;)
用CMD做telnet之后提示
CentOS Linux release 6.0 (Final)
Kernel 2.6.32-71.el6.i686 on an i686
login:
登录之后提示
Last login: Mon Sep 10 16:34:06 from 172.28.101.1
-bash: /sbin:/usr/sbin:/usr/local/sbin:/usr/kerberos/sbin: 没有那个文件或目录
[sunkaizhan@genuine-opto-bob ~]$
au3代码Global $host, $port, $delay, $user, $pass, $sk, $ack
$host = "172.28.101.9";交换机IP
$port = 23;telnet默认端口
$delay = 500 ; 等待时间/毫秒
$user = "test";用户名
$pass = "123456";密码
TCPStartup()
$sk = TCPConnect($host, $port)
If $sk = -1 Then
MsgBox(0, "", "Cannot connect1")
Exit
EndIf
Sleep($delay)
$ack = TCPRecv($sk, 150)
TrayTip("", $ack, 10)
MsgBox (0,"",$ack)
If StringInStr($ack, "login:") >= 1 Then ;如果连接成功,设备返回有关信息
;下面将发送用户名
Sleep($delay)
TCPSend($sk, "y" & @CRLF)
Sleep($delay)
TCPSend($sk, $user & @CRLF)
Sleep($delay)
$ack = TCPRecv($sk, 80)
TrayTip("", $ack, 10)
; 和密码
Sleep($delay)
TCPSend($sk, $pass & @CRLF)
Sleep($delay)
$ack = TCPRecv($sk, 80)
TrayTip("", $ack, 10)
Else
MsgBox(0, "", "Cannot connect2")
Exit
EndIf
If StringInStr($ack, "[root@test ~]$") = 0 Then ; 登陆成功后设备返回的信息
MsgBox(0, "Error", "Access denied")
Exit
EndIf
; 下面你可以发送一些命令给设备,比如重启
Sleep($delay)
TCPSend($sk, "dir" & @CRLF)
Sleep($delay)
$ack = TCPRecv($sk, 2000)
MsgBox(0,"Running processes", $ack)
TCPCloseSocket($sk)
TCPShutdown()
Exit
|