Public Sub iptest()
Ping ("10.18.22.5")
Cells(1, 1) = blnok
End Sub
Function Ping(strAddr As String) As String
blnok = GetObject("winmgmts:").Get("NetDiagnostics=@").Ping(strAddr, Ping)
End Function作者: c_c_lai 時間: 2013-8-26 16:35
Public Sub iptest()
Columns("B:B").Select
Selection.ClearContents
Range("A1").Select
費時 = Timer
i = 1
Do While Cells(i, 1) <> ""
Cells(i, 2) = Ping(Cells(i, 1))
i = i + 1
Loop
Cells(1, 3) = Timer - 費時
End Sub
Private Function Ping(strAddr As String) As String
Dim strTmpFile As String
strTmpFile = Environ("TEMP") & "\PingResult.txt" ' 準備建暫存檔在 Windows Temp 目錄下
CreateObject("WScript.Shell").Run Environ("COMSPEC") & " /c PING -n 1 " & strAddr & " > " & strTmpFile, 0, True
Ping = CreateObject("Scripting.FileSystemObject").OpenTextFile(strTmpFile).ReadAll
Ping = Replace(Ping, vbCrLf, "", 1)
On Error Resume Next
Kill strTm
End Function作者: c_c_lai 時間: 2013-8-28 09:37
Public Sub 工作()
'測試ip
費時 = Timer
列 = 1
For i = 1 To 10
批次檔 = "d:\iptest\" & i & ".BAT"
a = Shell(批次檔, 0)
Next i
休息 = Timer
Do While Timer - 休息 < 1
DoEvents
Loop
'讀取結果
For i = 1 To 10
文字檔 = "d:\iptest\" & i & ".TXT"
代碼 = FreeFile ' 取得未使用的檔案代碼。
Open 文字檔 For Input As #代碼
cells(i, 2) = Input(120, #代碼)
Close #代碼 ' 關閉檔案。
Next i
cells(1, 3) = Timer - 費時
End Sub作者: c_c_lai 時間: 2013-8-28 14:31
Sub Test()
Columns("B:C").Select
Selection.ClearContents
費時 = Timer
For i = 1 To 10
RetVal = Shell("command.com /c Ping -n 1 " & Cells(i, 1) & " > " & ThisWorkbook.Path & "\" & i & ".txt")
Next i
休息 = Timer
Do While Timer - 休息 < 2
DoEvents
Loop
For i = 1 To 10
文字檔 = ThisWorkbook.Path & "\" & i & ".TXT"
代碼 = FreeFile ' 取得未使用的檔案代碼。
Open 文字檔 For Input As #代碼
字長 = LOF(代碼)
Cells(i, 2) = Input(字長, #代碼)
Close #代碼 ' 關閉檔案。
Next i
Cells(1, 3) = Timer - 費時
End Sub作者: c_c_lai 時間: 2013-8-28 16:14