VB读取 C:\ipconfig.txt中关键字为“192.168.1."(IP最后一位是动态)的IP并存入IP.TXT中,如何写?

2020-06-06 社会 88阅读
Dim str As String
str = ""
Dim checkStr As String
checkStr = "192.168.1."
Dim prefix As String
prefix = "route add 10.50.82.0 mask 255.255.255.0 "
Dim idx As Integer
Open "c:\ipconfig.txt" For Input As #1
Open "c:\ip.txt" For Output As #2
Do
idx = -1
Input #1, str
idx = InStr(str, checkStr)
If idx > 0 Then
Print #2, Mid(str, idx)
End If
Loop Until EOF(1)
Close #2
Close #1
-- 把ip写进bat file 里, 然后执行
Open "c:\ip.bat" For Output As #3
Open "c:\ip.txt" For Input As #4
Do
Input #1, str
Print #2, prefix & str
Loop Until EOF(4)
Close #3
Close #4
Call Shell("c:\ip.bat", vbNormalFocus)
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com