String VBS剪切字符串的第一行
我有以下Visual Basic代码段:String VBS剪切字符串的第一行,string,vbscript,String,Vbscript,我有以下Visual Basic代码段: Option Explicit Dim objshell, strCmd, objExec, strLine, strIP set objShell = CreateObject("Wscript.Shell") strCmd = "%comspec% /c nslookup LT1130" Set objExec = objShell.Exec(strCmd) Do Until objExec.StdOut.
Option Explicit
Dim objshell, strCmd, objExec, strLine, strIP
set objShell = CreateObject("Wscript.Shell")
strCmd = "%comspec% /c nslookup LT1130"
Set objExec = objShell.Exec(strCmd)
Do Until objExec.StdOut.AtEndOfStream
strLine = objExec.StdOut.ReadLine()
If (Left(strLine, 8) = "Address:") Then
strIP = Trim(Mid(strLine, 11))
Wscript.Echo strIP
End If
Loop
输出2行。第一行是我的DNS服务器的IP地址,第二行是解析的IP地址
如何剪切包含DNS服务器IP地址的第一行,并仅输出包含解析IP地址的第二行
(如果可能的话,不使用临时文本文件)刚刚在我这边测试了这段修改过的代码,它可以工作5/5
刚刚在我这方面测试了这个修改过的代码,它可以正常工作5/5
添加计数器并在其为零时跳过输出?添加计数器并在其为零时跳过输出?
Option Explicit
Dim objshell, strCmd, objExec, strLine, strIP ,CountLine,MyArrayLine
set objShell = CreateObject("Wscript.Shell")
CountLine = 0
strCmd = "%comspec% /c nslookup myip.opendns.com. resolver1.opendns.com |find ""Address:"""
Set objExec = objShell.Exec(strCmd)
Do Until objExec.StdOut.AtEndOfStream
strLine = objExec.StdOut.ReadLine()
CountLine = CountLine + 1
If Instr(strLine,":") > 0 Then
MyArrayLine = Split(strLine,":")
strIP = Trim(MyArrayLine(1))
If CountLine = 2 Then
Wscript.Echo "My External IP Address : " & strIP
End If
End If
Loop