我在这里发布的另一个问题是获取我的外部IP,然后将其telnet到设备。
在Matt用户的大力帮助下,我成功地做到了这一点,但现在我对如何改进和更改代码有一些疑问。我的代码已经遵循:
Option Explicit
Dim objHTTP : Set objHTTP = WScript.CreateObject("MSXML2.ServerXmlHttp")
objHTTP.Open "GET", "http://icanhazip.com", False
objHTTP.Send
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
WshShell.SendKeys "telnet domain.com 9999"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "p"
WshShell.SendKeys "a"
WshShell.SendKeys "s"
WshShell.SendKeys "s"
WshShell.SendKeys "w"
WshShell.SendKeys "o"
WshShell.SendKeys "r"
WshShell.SendKeys "d"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "1"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
Function IPAddressToCharArray(pIpAddress)
Dim intCounter
Dim intLen
Dim singleCharacter
Dim strFormattedIpAddress
Dim arrChars()
' Remove the periods
' strFormattedIpAddress = Replace(pIpAddress,".","")
' Set the array length
intLen = Len(strFormattedIpAddress)-1
redim arrChars(intLen)
' Cycle through the string
For intCounter = 0 to intLen
' Capture the current character.
arrChars(intCounter) = Mid(strFormattedIpAddress, intCounter + 1,1)
Next
IPAddressToCharArray = arrChars
End Function
For Each strSingleCharacter in IPAddressToCharArray(objHTTP.ResponseText)
WshShell.SendKeys strSingleCharacter
Next
Set objWSHShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 2000
objWSHShell.SendKeys objHTTP.ResponseText
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WScript.Quit
Set objHTTP = Nothing
第一个问题 - 我在这个论坛中读过像瘟疫一样的发送键,我很同意,但是替代方案是什么,因为telnet只能通过输入键来编写,或者是否有命令我可以发送没有典型的模拟?
第二个问题 - 在我的例子中,我有一个telnet会话。我可以一个接一个地发出其他telnet会话,这意味着当一个完成,另一个星,在同一个scrpt中,或者我是否需要为每个telnet会话创建不同的文件然后发布它们?
第三 - 有没有办法通过sendkeys telnet命令(如果没有找到另一种方式),但在后台,所以如果我按下窗口打开的东西,它不会开始向其他窗口发送密钥?
提前感谢任何可以帮助我的人。