ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/host/vb_net_test/nettest.frm
Revision: 1.30
Committed: Wed Feb 28 11:59:54 2001 UTC (23 years, 2 months ago) by pjm2
Branch: MAIN
Changes since 1.29: +4 -0 lines
Log Message:
Minor changes.

File Contents

# User Rev Content
1 pjm2 1.1 VERSION 5.00
2     Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
3 pjm2 1.11 Object = "{33155A3D-0CE0-11D1-A6B4-444553540000}#1.0#0"; "SysTray.ocx"
4 pjm2 1.1 Begin VB.Form Form1
5 pjm2 1.17 BorderStyle = 3 'Fixed Dialog
6 pjm2 1.10 Caption = "i-scream Winhost"
7 pjm2 1.27 ClientHeight = 1185
8 pjm2 1.1 ClientLeft = 45
9 pjm2 1.17 ClientTop = 330
10 pjm2 1.12 ClientWidth = 4710
11 pjm2 1.20 Icon = "nettest.frx":0000
12 pjm2 1.1 LinkTopic = "Form1"
13     MaxButton = 0 'False
14 pjm2 1.17 MinButton = 0 'False
15 pjm2 1.27 ScaleHeight = 1185
16 pjm2 1.12 ScaleWidth = 4710
17 pjm2 1.1 ShowInTaskbar = 0 'False
18 pjm2 1.24 StartUpPosition = 2 'CenterScreen
19     Visible = 0 'False
20 pjm2 1.26 Begin VB.CommandButton Command1
21     Caption = "more"
22     Height = 255
23     Left = 3960
24     TabIndex = 8
25     Top = 840
26     Width = 615
27     End
28     Begin VB.TextBox Text1
29     Height = 2055
30     Left = 120
31     Locked = -1 'True
32     MultiLine = -1 'True
33     ScrollBars = 2 'Vertical
34     TabIndex = 7
35     Top = 1200
36     Width = 4455
37     End
38 pjm2 1.11 Begin VB.CommandButton Hide
39 pjm2 1.27 Caption = "hide"
40     Height = 255
41     Left = 3960
42 pjm2 1.24 TabIndex = 6
43 pjm2 1.27 Top = 480
44     Width = 615
45 pjm2 1.11 End
46     Begin SysTray.SystemTray SystemTray
47 pjm2 1.26 Left = 2520
48     Top = 4200
49 pjm2 1.11 _ExtentX = 847
50     _ExtentY = 847
51     SysTrayText = "i-scream Winhost"
52     IconFile = 0
53     End
54 pjm2 1.8 Begin VB.Timer Timer1
55 pjm2 1.26 Left = 3120
56     Top = 4200
57 pjm2 1.1 End
58 pjm2 1.10 Begin VB.CommandButton Reconfigure
59     Caption = "Reconfigure with FilterManager"
60 pjm2 1.12 Height = 375
61 pjm2 1.26 Left = 840
62 pjm2 1.10 TabIndex = 0
63 pjm2 1.26 Top = 3480
64 pjm2 1.10 Width = 2895
65 pjm2 1.1 End
66 pjm2 1.5 Begin MSWinsockLib.Winsock TCPSock
67 pjm2 1.26 Left = 4080
68     Top = 4200
69 pjm2 1.1 _ExtentX = 741
70     _ExtentY = 741
71     _Version = 393216
72     End
73 pjm2 1.5 Begin MSWinsockLib.Winsock UDPSock
74 pjm2 1.26 Left = 3600
75     Top = 4200
76 pjm2 1.1 _ExtentX = 741
77     _ExtentY = 741
78     _Version = 393216
79     Protocol = 1
80     End
81 pjm2 1.9 Begin VB.Label Label2
82     Alignment = 1 'Right Justify
83     Caption = "Next heartbeat:"
84 pjm2 1.8 Height = 255
85 pjm2 1.26 Left = 120
86 pjm2 1.24 TabIndex = 5
87 pjm2 1.26 Top = 480
88 pjm2 1.9 Width = 1455
89 pjm2 1.8 End
90 pjm2 1.9 Begin VB.Label Label1
91     Alignment = 1 'Right Justify
92     Caption = "Next UDP packet:"
93 pjm2 1.8 Height = 255
94 pjm2 1.24 Left = 120
95     TabIndex = 4
96 pjm2 1.9 Top = 120
97     Width = 1455
98 pjm2 1.8 End
99 pjm2 1.9 Begin VB.Label Label4
100 pjm2 1.10 BorderStyle = 1 'Fixed Single
101 pjm2 1.9 Caption = "0"
102 pjm2 1.7 Height = 255
103 pjm2 1.26 Left = 1680
104 pjm2 1.24 TabIndex = 3
105 pjm2 1.26 Top = 480
106 pjm2 1.9 Width = 615
107 pjm2 1.7 End
108 pjm2 1.9 Begin VB.Label Label3
109 pjm2 1.10 BorderStyle = 1 'Fixed Single
110 pjm2 1.9 Caption = "0"
111 pjm2 1.7 Height = 255
112 pjm2 1.24 Left = 1680
113     TabIndex = 2
114 pjm2 1.9 Top = 120
115     Width = 615
116 pjm2 1.7 End
117 pjm2 1.6 Begin VB.Label Status
118 pjm2 1.12 Alignment = 2 'Center
119 pjm2 1.6 Caption = "Status:"
120 pjm2 1.1 Height = 255
121 pjm2 1.18 Left = 0
122 pjm2 1.24 TabIndex = 1
123 pjm2 1.26 Top = 840
124     Width = 3855
125 pjm2 1.1 End
126     End
127     Attribute VB_Name = "Form1"
128     Attribute VB_GlobalNameSpace = False
129     Attribute VB_Creatable = False
130     Attribute VB_PredeclaredId = True
131     Attribute VB_Exposed = False
132 pjm2 1.15 ' For the system tray bits
133 pjm2 1.4 Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
134     Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
135    
136     Dim filterManagerHostname As String
137 pjm2 1.18 Dim filterManagerTCPPort As Long
138 pjm2 1.4
139 pjm2 1.13 Dim seqNo As Long
140     Dim machineName As String
141    
142 pjm2 1.2 Dim filterHostname As String
143 pjm2 1.3 Dim filterTCPPort As Integer
144     Dim filterUDPPort As Integer
145     Dim fileList As String
146     Dim lastModified As String
147 pjm2 1.2
148 pjm2 1.7 Dim UDPUpdateTime As Integer
149     Dim TCPUpdateTime As Integer
150    
151 pjm2 1.2 Dim protocolVersion As String
152     Dim connected As Boolean
153 pjm2 1.16
154 pjm2 1.21 Dim CUpTime As New CUpTime
155 pjm2 1.25 Dim wksta As New CNetWksta
156 pjm2 1.16
157 pjm2 1.26 Dim windowBig As Boolean
158    
159 pjm2 1.1 Dim responseNumber As Integer
160    
161 pjm2 1.26 Private Sub Command1_Click()
162    
163     ' Toggle visibility of the debug output.
164    
165     If windowBig Then
166     Form1.Height = 1500
167     windowBig = False
168     Else
169     Form1.Height = 4350
170     windowBig = True
171     End If
172    
173     End Sub
174    
175 pjm2 1.2 Private Sub Form_Load()
176 pjm2 1.13
177 pjm2 1.22 If App.PrevInstance Then
178     x = MsgBox("There is already an i-scream Winhost running on this machine.", 48, "i-scream host already running")
179 pjm2 1.25 End
180 pjm2 1.22 End If
181    
182 pjm2 1.2 protocolVersion = "1.1"
183 pjm2 1.13
184 pjm2 1.10 Status.Caption = "Loading"
185 pjm2 1.21 Form1.Caption = "i-scream Winhost " & protocolVersion
186    
187     CUpTime.Init
188    
189     If CUpTime.isWin9x Then
190 pjm2 1.25 x = MsgBox("Sorry, the i-scream host can only be used to monitor servers (i.e. not Win9x)", 48, "Not a server")
191 pjm2 1.21 End
192     End If
193 pjm2 1.6
194 pjm2 1.26 windowBig = False
195    
196 pjm2 1.4 ''''TEMP
197 pjm2 1.18 'filterManagerHostname = "killigrew.ukc.ac.uk"
198     'filterManagerTCPPort = 4567
199 pjm2 1.13 ''''' END TEMP
200 pjm2 1.4
201 pjm2 1.18 'GoTo skip
202 pjm2 1.4 On Error GoTo iniError
203     Dim buf As String * 256
204     Dim length As Long
205 pjm2 1.18 length = GetPrivateProfileString("i-scream Winhost", "FilterManager", "<no value>", buf, Len(buf), App.Path & "/winhost.ini")
206 pjm2 1.4 filterManagerHostname = Left$(buf, length)
207 pjm2 1.18 length = GetPrivateProfileInt("i-scream Winhost", "FilterManagerPort", 0, App.Path & "/winhost.ini")
208     filterManagerTCPPort = length
209 pjm2 1.25 If filterManagerHostname = "" Then
210     GoTo iniError
211     End If
212 pjm2 1.20 On Error GoTo 0
213 pjm2 1.13 skip:
214    
215 pjm2 1.18 Status.Caption = "Connecting to Filter Manager " & filterManagerHostname & ":" & filterManagerTCPPort
216 pjm2 1.13 Reconfigure_Click
217 pjm2 1.6
218 pjm2 1.20 SystemTray.Icon = Val(Form1.Icon)
219 pjm2 1.15 SystemTray.Action = 0
220    
221    
222 pjm2 1.4 Exit Sub
223    
224     iniError:
225 pjm2 1.18 x = MsgBox("The i-scream Winhost could not read the correct settings from the winhost.ini file. Please correct these and try again. " & Err.Description, 48, "Configuration not found")
226 pjm2 1.4 End
227    
228     End Sub
229    
230 pjm2 1.10 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
231 pjm2 1.11 x = MsgBox("Are you sure you want to shut down the Winhost? This will stop your computer sending information to the i-scream Central Monitoring System.", vbYesNo, "i-scream Winhost")
232 pjm2 1.10 If x = 7 Then
233     Cancel = True
234 pjm2 1.15 Else
235     SystemTray.Action = 2
236 pjm2 1.10 End If
237    
238     End Sub
239    
240 pjm2 1.11 Private Sub Hide_Click()
241     Form1.Visible = False
242     SystemTray.Icon = Val(Form1.Icon)
243     End Sub
244    
245 pjm2 1.30 Private Sub Image1_Click()
246    
247     End Sub
248    
249 pjm2 1.10 Private Sub Reconfigure_Click()
250     ' establish a TCP connection to a filtermanager
251     connected = False
252     TCPSock.Close
253     TCPSock.Connect filterManagerHostname, filterManagerTCPPort
254 pjm2 1.11 End Sub
255    
256    
257    
258     Private Sub SystemTray_MouseDblClk(ByVal Button As Integer)
259    
260     Form1.Visible = True
261     Form1.SetFocus
262    
263 pjm2 1.10 End Sub
264    
265 pjm2 1.5 Private Sub TCPSock_Connect()
266 pjm2 1.6
267     responseNumber = 0
268 pjm2 1.1
269 pjm2 1.3 ' Send something as soon as we connect to the server.
270     If connected = False Then
271     ' contact the FilterManager
272 pjm2 1.5 TCPSock.SendData "STARTCONFIG" & vbCrLf
273 pjm2 1.3 Else
274     ' Contact the Filter
275 pjm2 1.5 TCPSock.SendData "HEARTBEAT" & vbCrLf
276 pjm2 1.3 End If
277 pjm2 1.1
278     End Sub
279    
280 pjm2 1.5 Private Sub TCPSock_DataArrival(ByVal bytesTotal As Long)
281 pjm2 1.1
282     responseNumber = responseNumber + 1
283    
284     ' Get the line from the server.
285 pjm2 1.5 TCPSock.GetData response, vbString, bytesTotal
286 pjm2 1.1
287     ' Remove linefeeds and returns from the line.
288     response = Replace(response, Chr(13), "")
289     response = Replace(response, Chr(10), "")
290    
291 pjm2 1.2 If connected = False Then
292     ' Perform TCP configuration (1.1)
293     On Error GoTo configError
294     Select Case responseNumber
295     Case 1:
296     If Not response = "OK" Then GoTo configError
297 pjm2 1.5 TCPSock.SendData "LASTMODIFIED" & vbCrLf
298 pjm2 1.26 Text1.Text = "Requesting configuration from FilterManager:- " & vbCrLf
299     Text1.Text = Text1.Text & response & vbCrLf
300 pjm2 1.2 Case 2:
301     If response = "ERROR" Then GoTo configError
302 pjm2 1.3 lastModified = response
303 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
304 pjm2 1.5 TCPSock.SendData "FILELIST" & vbCrLf
305 pjm2 1.29 ' New addition to the protocol.
306 pjm2 1.2 Case 3:
307     If response = "ERROR" Then GoTo configError
308 pjm2 1.3 fileList = response
309 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
310 pjm2 1.29 TCPSock.SendData "FQDN" & vbCrLf
311     Case 4:
312     If response = "ERROR" Then GoTo configError
313     Text1.Text = Text1.Text & response & vbCrLf
314     machineName = response
315 pjm2 1.5 TCPSock.SendData "UDPUpdateTime" & vbCrLf
316 pjm2 1.29 Case 5:
317 pjm2 1.2 If response = "ERROR" Then GoTo configError
318 pjm2 1.7 UDPUpdateTime = response
319 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
320 pjm2 1.5 TCPSock.SendData "TCPUpdateTime" & vbCrLf
321 pjm2 1.29 Case 6:
322 pjm2 1.2 If response = "ERROR" Then GoTo configError
323 pjm2 1.7 TCPUpdateTime = response
324 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
325 pjm2 1.5 TCPSock.SendData "ENDCONFIG" & vbCrLf
326 pjm2 1.29 Case 7:
327 pjm2 1.2 If Not response = "OK" Then GoTo configError
328 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
329 pjm2 1.5 TCPSock.SendData "FILTER" & vbCrLf
330 pjm2 1.29 Case 8:
331 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
332 pjm2 1.2 'we got a filter list here.
333     readTo = 0
334     ' get hostname
335     readTo = InStr(1, response, ";", vbBinaryCompare)
336     filterHostname = Mid(response, 1, readTo - 1)
337     response = Mid(response, readTo + 1, Len(response))
338     ' get UDP Port number
339     readTo = InStr(1, response, ";")
340     filterUDPPort = Mid(response, 1, readTo - 1)
341     response = Mid(response, readTo + 1, Len(response))
342     ' get TCP Port number
343     filterTCPPort = response
344 pjm2 1.5 TCPSock.SendData "END" & vbCrLf
345 pjm2 1.29 Case 9:
346 pjm2 1.2 If Not response = "OK" Then GoTo configError
347     connected = True
348     responseNumber = 0
349 pjm2 1.5 TCPSock.Close
350 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
351 pjm2 1.24 'Text4.Text = Text4.Text & vbCrLf & " <closed>"
352 pjm2 1.10 Status.Caption = "Configuration successful"
353 pjm2 1.8 Label3.Caption = UDPUpdateTime
354     Label4.Caption = TCPUpdateTime
355     Timer1.Interval = 1000
356 pjm2 1.2 End Select
357     Else
358     ' Perform a heartbeat (1.1)
359     On Error GoTo heartbeatError
360     Select Case responseNumber
361     Case 1:
362 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
363 pjm2 1.26 Text1.Text = "Performing heartbeat: -" & vbCrLf
364     Text1.Text = Text1.Text & response & vbCrLf
365 pjm2 1.5 TCPSock.SendData "CONFIG" & vbCrLf
366 pjm2 1.2 Case 2:
367 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
368 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
369 pjm2 1.5 TCPSock.SendData fileList & vbCrLf
370 pjm2 1.2 Case 3:
371 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
372 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
373 pjm2 1.5 TCPSock.SendData lastModified & vbCrLf
374 pjm2 1.2 Case 4:
375 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
376 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
377 pjm2 1.5 TCPSock.SendData "ENDHEARTBEAT" & vbCrLf
378 pjm2 1.2 Case 5:
379 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
380 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
381 pjm2 1.5 TCPSock.Close
382 pjm2 1.10 Status.Caption = "Heartbeat sent successfully."
383 pjm2 1.2 End Select
384    
385     End If
386    
387    
388     Exit Sub
389    
390     configError:
391 pjm2 1.10 Status.Caption = "FAILED to get configuration"
392 pjm2 1.8 Exit Sub
393 pjm2 1.2 heartbeatError:
394 pjm2 1.10 Status.Caption = "Heatbeat FAILED"
395 pjm2 1.8 Exit Sub
396 pjm2 1.1 End Sub
397 pjm2 1.5
398 pjm2 1.8 Private Sub Timer1_Timer()
399    
400     Label3.Caption = Label3.Caption - 1
401     Label4.Caption = Label4.Caption - 1
402    
403 pjm2 1.10 Status.Caption = ""
404 pjm2 1.8
405     If Label3.Caption < 1 Then
406 pjm2 1.15
407     ' prepare the contents of the XML packet.
408     seqNo = seqNo + 1
409 pjm2 1.26
410     ' Comment this line in the next protocol
411 pjm2 1.29 'machineName = TCPSock.LocalHostName
412 pjm2 1.26
413 pjm2 1.16 LocalIP = TCPSock.LocalIP
414 pjm2 1.14 packetDate = Date2Num()
415 pjm2 1.15
416    
417     Dim verinfo As OSVERSIONINFO
418     verinfo.dwOSVersionInfoSize = Len(verinfo)
419     ret% = GetVersionEx(verinfo)
420     If ret% = 0 Then
421     MsgBox "Error getting Windows version Information"
422     End
423     End If
424    
425 pjm2 1.21 osName = GetVersion()
426 pjm2 1.15 osVersionMajor = verinfo.dwMajorVersion
427     osVersionMinor = verinfo.dwMinorVersion
428     osBuild = verinfo.dwBuildNumber
429    
430     Dim sysinfo As SYSTEM_INFO
431     GetSystemInfo sysinfo
432     Select Case sysinfo.dwProcessorType
433     Case PROCESSOR_INTEL_386
434     processorType = "Intel 386"
435     Case PROCESSOR_INTEL_486
436     processorType = "Intel 486"
437     Case PROCESSOR_INTEL_PENTIUM
438     processorType = "Intel Pentium variant"
439     Case PROCESSOR_MIPS_R4000
440     processorType = "MIPS R4000"
441     Case PROCESSOR_ALPHA_21064
442     processorType = "DEC Alpha 21064"
443     Case Else
444     processorType = "(unknown)"
445     End Select
446    
447     Dim memsts As MEMORYSTATUS
448     Dim memory&
449     GlobalMemoryStatus memsts
450     memory& = memsts.dwTotalPhys
451 pjm2 1.29 memTotal = memory& \ 1048576
452 pjm2 1.15 memory& = memsts.dwAvailPhys
453 pjm2 1.29 memFree = memory& \ 1048576
454 pjm2 1.15 memory& = memsts.dwTotalVirtual
455 pjm2 1.29 swapTotal = memory& \ 1048576
456 pjm2 1.15 memory& = memsts.dwAvailVirtual
457 pjm2 1.29 swapFree = memory& \ 1048576
458 pjm2 1.15
459 pjm2 1.25 uptime = CUpTime.MilliSecs \ 1000
460 pjm2 1.19
461 pjm2 1.23 CUpTime.Capture
462     cpu_time = CUpTime.CPUTime
463     percent_idle = CUpTime.PercentIdle
464    
465 pjm2 1.28 userCount = wksta.LoggedOnUsers
466    
467 pjm2 1.15 ' build the contents of the XML packet
468 pjm2 1.16 xml = "<packet seq_no=""" & seqNo & """ machine_name=""" & machineName & """ date=""" & packetDate & """ type=""data"" ip=""" & LocalIP & """>" & _
469 pjm2 1.15 "<os>" & _
470     "<name>" & osName & "</name>" & _
471     "<version>" & osVersionMajor & "</version>" & _
472     "<release>" & osBuild & "</release>" & _
473     "<platform>" & osName & "</platform>" & _
474     "<minor_version>" & osVersionMinor & "</minor_version>" & _
475     "<processor>" & processorType & "</processor>" & _
476 pjm2 1.19 "<uptime>" & uptime & "</uptime>" & _
477 pjm2 1.15 "</os>" & _
478 pjm2 1.28 "<users><count>" & userCount & "</count></users>" & _
479 pjm2 1.23 "<cpu><idle>" & percent_idle & "</idle><user>" & cpu_time & "</user></cpu>" & _
480 pjm2 1.15 "<memory><total>" & memTotal & "</total><free>" & memFree & "</free></memory>" & _
481     "<swap><total>" & swapTotal & "</total><free>" & swapFree & "</free></swap>" & _
482 pjm2 1.17 "</packet>"
483 pjm2 1.26 Text1.Text = "Last packet contained: -" & vbCrLf & xml
484 pjm2 1.8
485     ' Use the first winsock control to send a UDP packet.
486     UDPSock.RemoteHost = filterHostname
487     UDPSock.RemotePort = filterUDPPort
488     UDPSock.SendData xml
489 pjm2 1.10 Status.Caption = "UDP packet sent"
490 pjm2 1.8 Label3.Caption = UDPUpdateTime
491     End If
492    
493     If Label4.Caption < 1 Then
494     ' establish a TCP connection to a filter
495     TCPSock.Close
496     TCPSock.Connect filterHostname, filterTCPPort
497     Label4.Caption = TCPUpdateTime
498     End If
499    
500     End Sub
501 pjm2 1.13
502     Function Date2Num() As Long
503 pjm2 1.14 Dim x As Long
504     x = DateDiff("s", "1-1-1970", Now)
505     Date2Num = x
506 pjm2 1.13 End Function