本帖最后由 xiehuahere 于 2011-9-27 23:38 编辑
无论是TCPsend方式还是官网中的capture to text都能实现记录,你没认真研究吧。
此类帖子也不少了,我点到为止。
TCPSend() 只发送你指定的命令,与键盘输入无关。$delay = 300
$username = "root"
$passwd = ""
$cmd = "ping xx.xx.xx.xx"
TCPStartup()
$socket = TCPConnect($host, $port)
If $socket = -1 Then
MsgBox(48, "Error", "Connect fail.")
Exit
EndIf
Sleep(1000)
$ack = TCPRecv($socket, 500)
; verifying if the correct answer
If Not StringInStr($ack, "login") > 0 Then
MsgBox(48, "Warning", "Wait for login request timeout!")
Exit
EndIf
TCPSend($socket, $username & @CRLF)
Sleep($delay)
$ack = TCPRecv($socket, 80)
If Not StringInStr($ack, "Password") > 0 Then
MsgBox(48, "Warning", "Wait for password request timeout!")
Exit
EndIf
TCPSend($socket, $passwd & @CRLF)
Sleep($delay)
$ack = TCPRecv($socket, 80)
If Not StringInStr($ack, "# ") > 0 Then
MsgBox(48, "Warning", "login failed!")
Exit
EndIf
TCPSend($socket, $cmd & @CRLF)
Sleep(5000)
$ack = TCPRecv($socket, 300)
MsgBox(0, "", $ack)
最后通过msgbox看看ping命令返回的是什么吧,肯定是多行信息,而且有可能包含你发送的内容。
所以需要你做后续的字符串处理,可以用StringSplit() 将每行内容取出存入数组(分隔符指定为@CRLF,flag = 1),然后取出你要的那一行内容。 |