mbt masai
 
Welcome !
         

                                
After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 ping

Author Message
kytto

  • Total Posts : 29
  • Scores: 0
  • Reward points : 0
  • Joined: 2/23/2007
  • Status: offline
ping Tuesday, February 27, 2007 4:54 AM (permalink)
0
 
-------------------------------------------------------------------------------------------------------------
 x=ReportFileStatus("List.txt")
Function ReportFileStatus(filespec)
 Dim fso, msg
 Dim MyVar
 Set fso = CreateObject("Scripting.FileSystemObject")
 If (fso.FileExists(filespec)) Then
  Else
   MyVar = MsgBox ("""List.txt"" not found!" &_
   Chr (13) & "Make sure the list of computers is in the current directory" &_
   Chr (13) & "" &_
   Chr (13) & "       Have a Nice Day :)", 016, "Ping Script") &_
   WScript.Quit
 End If
 
End Function

 Set objExcel = CreateObject("Excel.Application")
  objExcel.Visible = True
  objExcel.Workbooks.Add
  intRow = 2
  objExcel.Cells(1, 1).Value = "Computer Name"
  objExcel.Cells(1, 2).Value = "Result"
 Set Fso = CreateObject("Scripting.FileSystemObject")
 Set InputFile = fso.OpenTextFile("List.Txt")
 Do While Not (InputFile.atEndOfStream)
  HostName = InputFile.ReadLine
 Set WshShell = WScript.CreateObject("WScript.Shell")
  Ping = WshShell.Run("ping -n 1 " & HostName, 0, True)
  objExcel.Cells(intRow, 1).Value = HostName
 Select Case Ping
  Case 0 objExcel.Cells(intRow, 2).Value = "On Line"
  Case 1 objExcel.Cells(intRow, 2).Value = "Off Line"
 End Select
  intRow = intRow + 1
 Loop
  objExcel.Range("A1:B1").Select
  objExcel.Selection.Interior.ColorIndex = 19
  objExcel.Selection.Font.ColorIndex = 11
  objExcel.Selection.Font.Bold = True
  objExcel.Cells.EntireColumn.AutoFit
wscript.echo "Ping Process as Terminated"
WScript.Quit
-------------------------------------------------------------------------------------------------------------
 
instead of excel, how can I have this result saved on txt (notepad)
 

#1
    Country73

    • Total Posts : 753
    • Scores: 10
    • Reward points : 0
    • Status: offline
    RE: ping Tuesday, February 27, 2007 5:18 AM (permalink)
    0
    GREEN is what can be deleted, while ORANGE is what I added.
    **Did not test out, just threw together.

    -------------------------------------------------------------------------------------------------------------
    x=ReportFileStatus("List.txt")

    Function ReportFileStatus(filespec)
        Dim fso, msg, MyVar
        'Dim MyVar
        Set fso = CreateObject("Scripting.FileSystemObject")
        IF NOT fso.FileExists(filespec) THEN
        'If (fso.FileExists(filespec)) Then
         'Else
            MyVar = MsgBox ("""List.txt"" not found!" &_
            Chr (13) & "Make sure the list of computers is in the current directory" &_
            Chr (13) & "" &_
            Chr (13) & "       Have a Nice Day :)", 016, "Ping Script") &_
            WScript.Quit
        End If
    End Function

    'Set objExcel = CreateObject("Excel.Application")
    '    objExcel.Visible = True
    '    objExcel.Workbooks.Add
    '    intRow = 2
    '    objExcel.Cells(1, 1).Value = "Computer Name"
    '    objExcel.Cells(1, 2).Value = "Result"


    Set Fso = CreateObject("Scripting.FileSystemObject")
    Set InputFile = fso.OpenTextFile("List.Txt")

    Set MyInfo = fso.OpenTextFile("File_to_store_information.txt",8,TRUE)


    DO UNTIL InputFile.AtEndOfStream
    'Do While Not (InputFile.atEndOfStream)
        HostName = InputFile.ReadLine
        Set WshShell = WScript.CreateObject("WScript.Shell")
        Ping = WshShell.Run("ping -n 1 " & HostName, 0, True)
        'objExcel.Cells(intRow, 1).Value = HostName
        Select Case Ping
            'Case 0 objExcel.Cells(intRow, 2).Value = "On Line"
            Case 0
                myMsg = HostName & VBTAB & "On Line"

            'Case 1 objExcel.Cells(intRow, 2).Value = "Off Line"
            Case 1
                myMsg = HostName & VBTAB & "Off Line"

        End Select
        'intRow = intRow + 1
        MyInfo.WriteLine myMsg
    Loop
    ' objExcel.Range("A1:B1").Select
    ' objExcel.Selection.Interior.ColorIndex = 19
    ' objExcel.Selection.Font.ColorIndex = 11
    ' objExcel.Selection.Font.Bold = True
    ' objExcel.Cells.EntireColumn.AutoFit

        MyInfo.Close
    SET MyInfo = NOTHING

    wscript.echo "Ping Process as Terminated"
    WScript.Quit 
    -------------------------------------------------------------------------------------------------------------
    #2
      kytto

      • Total Posts : 29
      • Scores: 0
      • Reward points : 0
      • Joined: 2/23/2007
      • Status: offline
      RE: ping Tuesday, February 27, 2007 5:26 AM (permalink)
      0
       

       
      thanks Country73
       
       
       
      #3
        kytto

        • Total Posts : 29
        • Scores: 0
        • Reward points : 0
        • Joined: 2/23/2007
        • Status: offline
        RE: ping Tuesday, February 27, 2007 5:45 AM (permalink)
        0
        btw, do you think thats the best ping command to use??
        #4
          Country73

          • Total Posts : 753
          • Scores: 10
          • Reward points : 0
          • Status: offline
          RE: ping Tuesday, February 27, 2007 6:27 AM (permalink)
          0
          Personally, I like to use:

          FUNCTION PingMe(strComputer)
              Set cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" + strComputer + "'")
                  For Each oPingResult In cPingResults
                      If oPingResult.StatusCode = 0 Then
                          Call OnlineEvent(strComputer)
                      Else
                          Call OfflineEvent(strComputer)
                      End If
                  Next
          END FUNCTION

          I try to use this function in all of my scripts, but here's an older one that I've used: (I know I have a few older ones, but this is one that I found pretty quickly)

          -----------------------------------------------------------------------
          FUNCTION ping(strComputer)
              SET oExec = oShell.Exec("nbtstat -a " & strComputer)

              strOutput = ""
              DO UNTIL oExec.StdOut.AtEndOfStream
                  strOutput = strOutput & oExec.StdOut.Read(1)
              LOOP

              IF INSTR(strOutput,"Host not found") > 0 THEN
                  call output(strComputer,"OFFLINE")
              ELSE
                  CALL NextStep(strComputer)
              END IF
          END FUNCTION
          -----------------------------------------------------------------------








          #5
            kytto

            • Total Posts : 29
            • Scores: 0
            • Reward points : 0
            • Joined: 2/23/2007
            • Status: offline
            RE: ping Tuesday, February 27, 2007 9:34 AM (permalink)
            0
            he always returns the value "On Line", even if the computer doesn't exists ;(
             
            regarding your code, how can I put it with an input file and an output log??
            #6
              dm_4ever

              • Total Posts : 3673
              • Scores: 82
              • Reward points : 0
              • Joined: 6/29/2006
              • Location: Orange County, California
              • Status: offline
              RE: ping Tuesday, February 27, 2007 9:46 AM (permalink)
              0
              You can try something like this.  Just remember that this requires the machine running it to be WinXP or Win2k3
               
               Option Explicit
               'On Error Resume Next
                
               Dim objFSO, objFile1, objFile2, strInputFile, strOutputFile, strHost
                
               Const ForReading = 1  :  Const ForWriting = 2  :  Const ForAppending = 8
                
               strInputFile = "list.txt"
               strOutputFile = "output.txt"
                
               Set objFSO = CreateObject("Scripting.FileSystemObject")
               Set objFile1 = objFSO.OpenTextFile(strInputFile, ForReading)
               Set objFile2 = objFSO.OpenTextFile(strOutputFile, ForAppending, True)
                
               Do Until objFile1.AtEndOfStream
                strHost = objFile1.ReadLine
                If Reachable(strHost) Then
                 objFile2.WriteLine strHost & vbTab & "Online"
                Else 
                 objFile2.WriteLine strHost & vbTab & "Offline"
                End If
               Loop
                
               Function Reachable(strComputer)
               '  On Error Resume Next
                
                Dim wmiQuery, objWMIService, objPing, objStatus
                
                wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strComputer & "'"
                
                Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
                Set objPing = objWMIService.ExecQuery(wmiQuery)
                
                For Each objStatus in objPing
                 If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
                  Reachable = False 'if computer is unreacable, return false
                 Else
                  Reachable = True 'if computer is reachable, return true
                 End If
                Next
               End Function
               

              dm_4ever

              My philosophy: K.I.S.S - Keep It Simple Stupid
              Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
              Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
              #7
                dm_4ever

                • Total Posts : 3673
                • Scores: 82
                • Reward points : 0
                • Joined: 6/29/2006
                • Location: Orange County, California
                • Status: offline
                RE: ping Tuesday, February 27, 2007 12:33 PM (permalink)
                0
                This version should work on Win2k and WinXP

                 Option Explicit
                 'On Error Resume Next
                 
                 Dim objFSO, objFile1, objFile2, strInputFile, strOutputFile, strHost
                 
                 Const ForReading = 1  :  Const ForWriting = 2  :  Const ForAppending = 8
                 
                 strInputFile = "list.txt"
                 strOutputFile = "output.txt"
                 
                 Set objFSO = CreateObject("Scripting.FileSystemObject")
                 Set objFile1 = objFSO.OpenTextFile(strInputFile, ForReading)
                 Set objFile2 = objFSO.OpenTextFile(strOutputFile, ForAppending, True)
                 
                 Do Until objFile1.AtEndOfStream
                     strHost = objFile1.ReadLine
                     If Reachable(strHost) Then
                         objFile2.WriteLine strHost & vbTab & "Online"
                     Else 
                         objFile2.WriteLine strHost & vbTab & "Offline"
                     End If
                 Loop
                 
                 objFile1.Close
                 objFile2.Close
                 
                 Function Reachable(strComputer)
                 '     On Error Resume Next
                 
                     Dim objShell, objExec, strCmd, strTemp
                     
                     strCmd = "ping -n 1 " & strComputer
                     
                     Set objShell = CreateObject("WScript.Shell")
                     Set objExec = objShell.Exec(strCmd)
                     strTemp = UCase(objExec.StdOut.ReadAll)
                     
                     If InStr(strTemp, "REPLY FROM") Then
                         Reachable = True 
                     Else
                         Reachable = False
                     End If
                 End Function
                 

                dm_4ever

                My philosophy: K.I.S.S - Keep It Simple Stupid
                Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
                Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
                #8
                  kytto

                  • Total Posts : 29
                  • Scores: 0
                  • Reward points : 0
                  • Joined: 2/23/2007
                  • Status: offline
                  RE: ping Tuesday, February 27, 2007 1:53 PM (permalink)
                  0
                  dm
                   
                   
                  thanks m8
                  #9

                    Online Bookmarks Sharing: Share/Bookmark

                    Jump to:

                    Current active users

                    There are 0 members and 1 guests.

                    Icon Legend and Permission

                    • New Messages
                    • No New Messages
                    • Hot Topic w/ New Messages
                    • Hot Topic w/o New Messages
                    • Locked w/ New Messages
                    • Locked w/o New Messages
                    • Read Message
                    • Post New Thread
                    • Reply to message
                    • Post New Poll
                    • Submit Vote
                    • Post reward post
                    • Delete my own posts
                    • Delete my own threads
                    • Rate post

                    2000-2012 ASPPlayground.NET Forum Version 3.8
                    mbt shoes www.wileywilson.com