· 8 years ago · Feb 19, 2018, 08:52 AM
1<html>
2 <head>
3
4 <hta:application
5 id="Ping"
6 applicationname="ping"
7 caption="Pingcaption"
8 showintaskbar="yes"
9 singleinstance="no"
10 sysmenu="yes">
11
12 <title>
13 Ping
14 </title>
15
16 <style type="text/css">
17
18 body {
19 text-align:center;
20 font-family:arial;
21 }
22
23 td {
24 padding:5px;
25 }
26
27 </style>
28
29 <script type="text/vbscript">
30
31 Sub ClearResults()
32 document.getElementById("status").value = ""
33 End Sub
34
35 Sub Ping()
36
37 'Variables to use
38 Dim PingType, intPackets, Shell, Hosts, strHost, strTargetFile, strCommand, StartTime, ReturnCode, EndTime, ResponseTime, strResponse, strLogFile
39
40 'Set the log file
41 strLogFile = "pinglog.txt"
42
43 ReDim Hosts(0)
44 'Determine if the ping is for one target or a list
45 set PingType = document.getElementById("ping_type")
46 PingType = PingType.value
47
48 'Get the amount of packets to send
49 set intPackets = document.getElementById("packets")
50 intPackets = intPackets.value
51
52 'Create shell object
53 Set Shell = createObject("wscript.shell")
54
55 'Create scripting object
56 Set objFSO = CreateObject("Scripting.FileSystemObject")
57
58 'Get the target to ping
59 If PingType = 1 Then
60 'Single target
61 ReDim Preserve Hosts(0)
62 set Hosts(0) = document.getElementById("target")
63 Hosts(0) = Hosts(0).value
64 Else
65 'Get the target file
66 set strTargetFile = document.getElementById("target_file")
67 strTargetFile = strTargetFile.value
68 'Check the file exists
69 If Not objFSO.FileExists(strTargetFile) Then
70 MsgBox "File does not exists"
71 Exit Sub
72 End If
73 'List of targets
74 Set objTextFile = objFSO.OpenTextFile(strTargetFile, 1)
75 strHosts = objTextFile.ReadAll
76 objTextFile.Close
77 Hosts = Split(strHosts, vbCrLf)
78 End If
79
80 'Loop through each target
81 For Each strHost in Hosts
82 'What to run in command line
83 strCommand = "ping -n " & intPackets & " -w 300 " & strHost
84
85 'Run command and get return code
86 'Start timing the ping
87 StartTime = Timer()
88 'Send the ping
89 ReturnCode = Shell.Run(strCommand, 0, True)
90 'Stop timing the ping
91 EndTime = Timer()
92 ResponseTime = FormatNumber(EndTime - StartTime, 2)
93
94 'Update the status box
95 'Ping response
96 '0 = pingable, 1 = no response
97 set strResponse = document.getElementById("status")
98 strResponse = strResponse.value
99 If ReturnCode = 0 Then
100 strResponse = strResponse & strHost & " was reached" & vbCrLf
101 Else
102 strResponse = strResponse & strHost & " could not be reached" & vbCrLf
103 End If
104 'Ping time
105 strResponse = strResponse & "Ping time " & ResponseTime & " second(s)" & vbCrLf
106 strResponse = strResponse & "---------------------------" & vbCrLf
107 document.getElementById("status").value = strResponse
108 Next
109
110 'Save results to logfile
111 Set objLogFile = objFSO.OpenTextFile(strLogFile, 8, True)
112 objLogFile.WriteLine("Ping results - " & Now)
113 objLogFile.WriteLine(strResponse)
114 objLogFile.Close
115
116 End Sub
117
118 </script>
119
120 </head>
121 <body>
122
123 <table>
124 <tr>
125 <td>Separate target</td>
126 <td><input type="text" id="target" value="127.0.0.1" /></td>
127 </tr>
128 <tr>
129 <td>List of targets</td>
130 <td><input type="text" id="target_file" value="C:\Users\Talor\iplist.txt" /></td>
131 </tr>
132 <tr>
133 <td>Ping type</td>
134 <td>
135 <select id="ping_type">
136 <option value="1">Separate</option>
137 <option value="2">List</option>
138 </select>
139 </td>
140 </tr>
141
142 <tr>
143 <td colspan="2" height="20"></td>
144 </tr>
145
146 <tr>
147 <td>No. of packets</td>
148 <td>
149 <select id="packets">
150 <option value="1">1</option>
151 <option value="2">2</option>
152 <option value="3">3</option>
153 <option value="4">4</option>
154 <option value="5">5</option>
155 </select>
156 </td>
157 </tr>
158 <tr>
159 <td>
160 <input type="button" value="Clear results" onClick="ClearResults()" />
161 </td>
162 <td>
163 <input type="button" value="Ping" onClick="Ping()" />
164 </td>
165 </tr>
166 <tr>
167 <td colspan="2">
168 <textarea id="status" cols="29" rows="5" readonly="readonly"></textarea>
169 </td>
170 </tr>
171 </table>
172
173 </body>
174</html>