Vb.net 需要我创建的Vb代码的帮助吗

Vb.net 需要我创建的Vb代码的帮助吗,vb.net,cmd,ping,Vb.net,Cmd,Ping,我正在做这个项目,我登录到路由器。ping到某个IP,如果我将数据包大小增加到4,O/p将显示百分比的结果&与需要时间的数据包计数-100相比,往返速度更快。因此需要代码,以便Vb像“屏蔽窗口”一样实时检查文件,如果在cmd窗口上找到百分比和往返,它将向cmd发送注销/退出/一些我的东西,并显示在MsgBox中 我需要Vb的帮助实时检查txt文件,如果没有找到,关闭文件,然后再次打开重新检查等等,或者可能像“屏蔽窗口” 请帮忙 我的原始代码如下 ==================== Pri

我正在做这个项目,我登录到路由器。ping到某个IP,如果我将数据包大小增加到4,O/p将显示百分比的结果&与需要时间的数据包计数-100相比,往返速度更快。因此需要代码,以便Vb像“屏蔽窗口”一样实时检查文件,如果在cmd窗口上找到百分比和往返,它将向cmd发送注销/退出/一些我的东西,并显示在MsgBox中

我需要Vb的帮助实时检查txt文件,如果没有找到,关闭文件,然后再次打开重新检查等等,或者可能像“屏蔽窗口”

请帮忙

我的原始代码如下

====================

Private Sub Runcode()
i = Shell("\windows\system32\cmd.exe", vbNormalFocus)

Dim MY_SERVER_IP As String
Dim LocalHost As String
Dim SourceIP As String
Dim DestinationIP As String
Dim Number As String
Dim Size As String
MY_SERVER_IP = "97.1.2.2"


Application.Wait (Now + TimeValue("0:00:02"))


SendKeys "telnet " & MY_SERVER_IP & " 6000 -f D:\Report\PING.txt{ENTER}"
Application.Wait (Now + TimeValue("0:00:02"))
SendKeys " Command to Login the Router"
Application.Wait (Now + TimeValue("0:00:02"))
SendKeys " PING IP: SRN=0, SN=14, SIPADDR=some_Source_IP , DESTIP=Some_Destination_IP, CONTPING=NO, TIMES=4, PKTSIZE=1400; "

Application.Wait (Now + TimeValue("0:00:50"))
' for short packet Number also i have to wait around 50 sec
' here currently Times=4 means it will recieve 4 reply packets which will show the result in 4 sec
' but same if i change it to 50 it wll take around 30-50 sec
Dim sFileName As String
Dim iFileNum As Integer
Dim sBuf As String
Dim Fields As String
Dim buffer As String
buffer = "round-trip"
sFileName = "D:\Report\PING.txt"
''//Does the file exist?
If Len(Dir$(sFileName)) = 0 Then
MsgBox ("File not Created")
End If
iFileNum = FreeFile()
Open sFileName For Input As iFileNum
Do While Not EOF(iFileNum)
Line Input #iFileNum, Fields
If Fields <> buffer Then
Call hint
Else
MsgBox ("didnt Work")
End If

Loop
Close iFileNum
End Sub
Close sFileName


Sub hint()

Dim myFile As String, text As String, textline As String, pkt As String, rndtrip As String

Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate "Telnet " & MY_SERVER_IP
objShell.SendKeys "Logout{enter}"
objShell.Application.Wait (Now + TimeValue("0:00:02"))
objShell.SendKeys "Exit{enter}"

myFile = "D:\Report\PING.txt"
Open myFile For Input As #1
Do Until EOF(1)
Line Input #1, textline
text = text & textline
Loop
Close #1


pkt = Trim(Mid(text, InStr(text, "Percent") + 0, (InStrRev(text, "packet") + 0) - (InStr(text, "Percent") + 1)))
rndtrip = Trim(Mid(text, InStr(text, "round-trip") + 0, (InStrRev(text, "ms") + 0) - (InStr(text, "round-trip") + 1)))

Call MsgBox("Percent : " & pkt & " Round-Trip : " & rndtrip & ".", vbOKOnly)

End Sub
====================
专用子运行码()
i=Shell(“\windows\system32\cmd.exe”,vbNormalFocus)
将我的\u服务器\u IP设置为字符串
将本地主机设置为字符串
Dim SourceIP作为字符串
Dim DestinationIP作为字符串
作为字符串的数字
像字符串一样变暗
我的服务器\u IP=“97.1.2.2”
Application.Wait(现在+时间值(“0:00:02”))
SendKeys“telnet”和MY_SERVER_IP&“6000-f D:\Report\PING.txt{ENTER}”
Application.Wait(现在+时间值(“0:00:02”))
SendKeys“登录路由器的命令”
Application.Wait(现在+时间值(“0:00:02”))
SendKeys“PING IP:SRN=0,SN=14,SIPADDR=some\u Source\u IP,DESTIP=some\u Destination\u IP,CONTPING=NO,TIMES=4,PKTSIZE=1400
Application.Wait(现在+时间值(“0:00:50”))
“对于短数据包编号,我也必须等待大约50秒
'此处当前时间=4表示它将接收4个回复数据包,这些数据包将在4秒内显示结果
“但如果我把它改成50它也需要30-50秒左右
将sFileName设置为字符串
作为整数的Dim iFileNum
作为字符串的Dim sBuf
将字段设置为字符串
将缓冲区设置为字符串
buffer=“往返”
sFileName=“D:\Report\PING.txt”
''//文件是否存在?
如果Len(Dir$(sFileName))=0,则
MsgBox(“未创建文件”)
如果结束
iFileNum=FreeFile()
打开sFileName作为iFileNum输入
不执行EOF时执行(iFileNum)
行输入#iFileNum,字段
如果字段缓冲,则
呼叫提示
其他的
MsgBox(“没有工作”)
如果结束
环
近缘
端接头
关闭sFileName
子提示()
Dim myFile作为字符串、text作为字符串、textline作为字符串、pkt作为字符串、rndtrip作为字符串
昏暗的奥布舍尔
设置objShell=CreateObject(“WScript.Shell”)
objShell.AppActivate“Telnet”和我的服务器IP
objShell.SendKeys“注销{enter}”
objShell.Application.Wait(现在+时间值(“0:00:02”))
objShell.SendKeys“退出{enter}”
myFile=“D:\Report\PING.txt”
打开myFile作为#1输入
直到EOF(1)为止
行输入#1,文本行
text=文本和文本行
环
关闭#1
pkt=Trim(中间(文本,仪表(文本,“百分比”)+0,(仪表(文本,“数据包”)+0)-(仪表(文本,“百分比”)+1)))
rndtrip=Trim(中间(文本,仪表(文本,“往返”)+0,(仪表(文本,“ms”)+0)-(仪表(文本,“往返”)+1)))
调用MsgBox(“百分比:”&pkt&“往返:”&rndtrip&“”,仅适用于vbOKOnly)
端接头

尝试添加此行。只有文件存在时,循环才会触发

 If System.IO.File.Exists(myFile )

 Do Until EOF(1)
 Line Input #1, textline
 text = text & textline
 Loop
 Close #1
 else 

 ' if the file is not there rerun the method. 
 Runcode()

 end if 
看见特别是关于写一个好标题的部分
写一个总结具体问题的标题