MSFN Forum: Ping Test - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ping Test Rate Topic: -----

#1 User is offline   Boston2012 

  • Group: Members
  • Posts: 8
  • Joined: 26-October 12
  • OS:Server 2008 x86
  • Country: Country Flag

Posted 09 January 2013 - 12:07 PM

Below is copy of script I'm using, the .csv file that shows results is showing "False" and should be showing "True". Any ideas why this is happening? I am able to manually ping 172.24.72.155 and getting replies.





'Option Explicit
On Error Resume Next

Dim strNewContents, strLine, objFile,SuccessFile,strSuccessFlag,SuccessCode,strCritcalFlag,CriticalFile
Dim objShell,strOS
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")

' Constants
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

strThisComputer = objNetwork.ComputerName
strFileOutput = "C:\TJXLogs\" & KMSPing & "KMSPing.csv"
strSuccessFlag = "C:\TJXLogs\Success.flag"
strOS = objShell.ExpandEnvironmentStrings("Win32_OperatingSystem") 

'Determine Operating System

for each objOS in GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
strOS=objOS.Caption
next

If LCase(strOS) = RTrim(LCase("Microsoft Windows 2000 Server")) Then
    strOS = "Windows 2000" 
ElseIf LCase(strOS) = Rtrim(LCase("Microsoft Windows Server 2008 Standard")) Then
	strOS = "Windows 2008"
Else
	strOS = "Windows 2008"
End If


If objFSO.FileExists(strFileOutput) Then
  Set objOutputFile = objFSO.OpenTextFile (strFileOutput, ForWriting)
Else
  Set objOutputFile = objFSO.CreateTextFile(strFileOutput, True)
End If
  
If Err <> 0 Then
  Wscript.Echo "Unable to open " & strFileOutput & " for output."
  WScript.Quit
End If

If objFSO.FileExists(strFileOutput) Then
  Set objOutputFile = objFSO.OpenTextFile (strFileOutput, ForWriting)
Else
  Set objOutputFile = objFSO.CreateTextFile(strFileOutput, False)
End If


strTarget = "172.24.72.155"  
If Ping(strTarget) = True Then
      strResult = "True"
	  set objsuccessflag = objFSO.CreateTextFile(strSuccessFlag, False)
Else
      strResult = "False"
End If

strFileOutput = "C:\TJXLogs\" & KMSPing & "KMSPing.csv"

  

Set objFSO = CreateObject("Scripting.FileSystemObject")
objOutputFile.Write """" & strThisComputer & """,""" & StrOS & ""","""  & strResult & """,""" & Now & """"& vbcrlf
objInFile.Close
objOutFile.Close

Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
	  
            Ping = False
      End If
	  
End Function




#2 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 09 January 2013 - 02:56 PM

Try this, it should show a true or false message

 Dim Act :Set Act = CreateObject("Wscript.Shell")
 Dim Ip, Return :Ip ="127.0.0.1" '-> Local Address Return Yes
 Ping(Ip)
 If Return Then
  WScript.Echo Return & ", Ip Reply : " & Ip
 Else
  WScript.Echo Return & ", Ip Reply : "  & Ip
 End If
  Function Ping(P) 
   If Act.Run("Ping -n 1 -w 300 " & P, 0, True) = 0 Then
    Return = True 
   Else
    Return = False
   End If  
  End Function



Rename DemoPing.vbs.txt to DemoPing.vbs to make active
Attached File  DemoPing.vbs.txt (408bytes)
Number of downloads: 4

#3 User is offline   Boston2012 

  • Group: Members
  • Posts: 8
  • Joined: 26-October 12
  • OS:Server 2008 x86
  • Country: Country Flag

Posted 09 January 2013 - 05:52 PM

Thanks for the reply. I'm still learning all this VB Scripting on the fly here, can you tell me where to add this data in my script? See below:

#4 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 09 January 2013 - 06:50 PM

I ment to try what I posted, the script you posted is a mess, so I want to start from scratch
and confirm that you can get either tue or false returns.

#5 User is offline   Boston2012 

  • Group: Members
  • Posts: 8
  • Joined: 26-October 12
  • OS:Server 2008 x86
  • Country: Country Flag

Posted 09 January 2013 - 08:53 PM

Just tried it and it's not showing any message?

#6 User is offline   Boston2012 

  • Group: Members
  • Posts: 8
  • Joined: 26-October 12
  • OS:Server 2008 x86
  • Country: Country Flag

Posted 09 January 2013 - 08:55 PM

Correction just got a "False" Reply

#7 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 09 January 2013 - 10:57 PM

What IP Address did you use, that a default local adresss for the computer
running the script.

Here what I done so far
 Dim Act :Set Act = CreateObject("Wscript.Shell")
 
 Dim Os
 Dim Ip, Return :Ip ="127.0.0.1" '-> Local Address Return Yes
 
 GetOsName()
 Ping(Ip)
  
 If Return Then
  MsgBox Return & ", Ip Reply : " & Ip & vbCrLf & Os,4128, "Test Positive"
 Else
  WScript.Echo Return & ", Ip Reply : "  & Ip,4128, "Test Negative"
 End If
 
'-> Get Os Name
  Function GetOsName()
   For Each Obj in GetObject("winmgmts:").InstancesOf(_
  "Win32_OperatingSystem")
   Os = Obj.Caption
  Next
  End Function
'-> Ping Computer
  Function Ping(P) 
   If Act.Run("Ping -n 1 -w 300 " & P, 0, True) = 0 Then
    Return = True 
   Else
    Return = False
   End If  
  End Function



Ip True Attached File  Ip_True.png (45.17K)
Number of downloads: 12 Ip FalseAttached File  Ip_False.png (36.82K)
Number of downloads: 8

#8 User is offline   DataCracker7899 

  • Newbie
  • Group: Members
  • Posts: 15
  • Joined: 02-January 13
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 17 February 2013 - 10:43 AM

ping it in batch just type
@echo off
color a
cls
ping 123.456.789

#9 User is offline   submix8c 

  • Inconceivable!
  • Group: Patrons
  • Posts: 3,244
  • Joined: 14-September 05
  • OS:none specified
  • Country: Country Flag

Posted 17 February 2013 - 11:12 AM

PLEASE, DataCracker7899. The OP specifically asked for VBScript, not BAT!

This is your "expertise" -

Quote

CSS 1 CSS 2 CSS 3 JavaScript 1.1 - 1.8.5 Batch HTML 4 HTML 5 C++ MySQL
Stick with those topics. ;)

This post has been edited by submix8c: 17 February 2013 - 11:12 AM


#10 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,433
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 17 February 2013 - 11:17 AM

View Postsubmix8c, on 17 February 2013 - 11:12 AM, said:

PLEASE, DataCracker7899. The OP specifically asked for VBScript, not BAT!

This is your "expertise" -

Quote

CSS 1 CSS 2 CSS 3 JavaScript 1.1 - 1.8.5 Batch HTML 4 HTML 5 C++ MySQL
Stick with those topics. ;)

Let me doubt about the "Batch" :whistle: :
http://www.msfn.org/...-in-batch-file/

jaclaz

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy