-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrmTrace2.frm
383 lines (336 loc) · 10.6 KB
/
FrmTrace2.frm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
VERSION 5.00
Begin VB.Form FrmTrace2
Caption = "Trace Route Built Into Windows"
ClientHeight = 3720
ClientLeft = 60
ClientTop = 345
ClientWidth = 7560
BeginProperty Font
Name = "Times New Roman"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Icon = "FrmTrace2.frx":0000
LinkTopic = "Form1"
MDIChild = -1 'True
ScaleHeight = 3720
ScaleWidth = 7560
Begin VB.Frame Frame1
Height = 1335
Left = 600
TabIndex = 4
Top = 0
Width = 6135
Begin VB.CheckBox Check1
Caption = "Resolve Ip To Host."
Height = 210
Left = 1080
TabIndex = 3
Top = 600
Value = 1 'Checked
Width = 1935
End
Begin VB.CommandButton TraceRT2
Caption = "Trace Route"
Default = -1 'True
Height = 255
Left = 3495
TabIndex = 1
Top = 240
Width = 1215
End
Begin VB.CommandButton Close
Caption = "Close"
Height = 255
Left = 4800
TabIndex = 2
Top = 240
Width = 1215
End
Begin VB.TextBox Host
Alignment = 2 'Center
Height = 300
Left = 840
TabIndex = 0
Top = 240
Width = 2535
End
Begin VB.Image Image1
Height = 480
Left = 4800
Picture = "FrmTrace2.frx":1982
Top = 840
Width = 480
End
Begin VB.Label lblIPHost
Alignment = 2 'Center
AutoSize = -1 'True
Caption = "IP/Host:"
Height = 225
Left = 120
TabIndex = 7
Top = 240
Width = 675
End
Begin VB.Label Label1
Alignment = 2 'Center
Height = 255
Left = 120
TabIndex = 6
Top = 960
Width = 4215
End
End
Begin VB.TextBox txtNS
BackColor = &H80000001&
BeginProperty Font
Name = "Arial"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000005&
Height = 2175
Left = 120
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 5
Top = 1440
Width = 7335
End
Begin VB.Timer Timer1
Interval = 100
Left = 6975
Top = 0
End
End
Attribute VB_Name = "FrmTrace2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'
' This project shows netstat instrution of commnand and show it in Windows Forms
'
' Declare all API, first
Private Declare Function CreatePipe Lib "kernel32" ( _
phReadPipe As Long, _
phWritePipe As Long, _
lpPipeAttributes As Any, _
ByVal nSize As Long) As Long
Private Declare Function ReadFile Lib "kernel32" ( _
ByVal hFile As Long, _
ByVal lpBuffer As String, _
ByVal nNumberOfBytesToRead As Long, _
lpNumberOfBytesRead As Long, _
ByVal lpOverlapped As Any) As Long
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadID As Long
End Type
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, _
lpProcessAttributes As Any, lpThreadAttributes As Any, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As Any, lpProcessInformation As Any) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Const SW_SHOWMINNOACTIVE = 7
Const STARTF_USESHOWWINDOW = &H1
Const INFINITE = -1&
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const STARTF_USESTDHANDLES = &H100&
' to execute the browser
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL = 1
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWDEFAULT = 10
'delay function
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Function ExecCmdPipe(ByVal CmdLine As String) As String
'Executes the command, and when it finish returns value to VB
Dim proc As PROCESS_INFORMATION, ret As Long, bSuccess As Long
Dim start As STARTUPINFO
Dim sa As SECURITY_ATTRIBUTES
Dim hReadPipe As Long, hWritePipe As Long
Dim bytesread As Long, mybuff As String
Dim i As Integer
Dim sReturnStr As String
' the lenght of the string must be 10 * 1024
mybuff = String(10 * 1024, Chr$(65))
sa.nLength = Len(sa)
sa.bInheritHandle = 1&
sa.lpSecurityDescriptor = 0&
ret = CreatePipe(hReadPipe, hWritePipe, sa, 0)
If ret = 0 Then
'===Error
ExecCmdPipe = "Error: CreatePipe failed. " & Err.LastDllError
Exit Function
End If
start.cb = Len(start)
start.hStdOutput = hWritePipe
start.dwFlags = STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW
start.wShowWindow = SW_SHOWMINNOACTIVE
' Start the shelled application:
ret& = CreateProcessA(0&, CmdLine$, sa, sa, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
If ret <> 1 Then
'===Error
sReturnStr = "Error: CreateProcess failed. " & Err.LastDllError
End If
' Wait for the shelled application to finish:
ret = WaitForSingleObject(proc.hProcess, INFINITE)
bSuccess = ReadFile(hReadPipe, mybuff, Len(mybuff), bytesread, 0&)
If bSuccess = 1 Then
sReturnStr = Left(mybuff, bytesread)
Else
'===Error
sReturnStr = "Error: ReadFile failed. " & Err.LastDllError
End If
ret = CloseHandle(proc.hProcess)
ret = CloseHandle(proc.hThread)
ret = CloseHandle(hReadPipe)
ret = CloseHandle(hWritePipe)
'returns to VB
ExecCmdPipe = sReturnStr
Me.Label1.Caption = "Done"
DoEvents
End Function
Private Sub Close_Click()
' #VBIDEUtilsERROR#
On Error GoTo ERROR_Close_Click
Unload Me
EXIT_Close_Click:
Exit Sub
' #VBIDEUtilsERROR#
ERROR_Close_Click:
Select Case MsgBox("Error " & Err.Number & ": " & Err.Description & vbCrLf & "in Close_Click" & vbCrLf & "The error occured at line: " & Erl, vbAbortRetryIgnore + vbCritical, "Error")
Case vbAbort
Screen.MousePointer = vbDefault
Resume EXIT_Close_Click
Case vbRetry
Resume
Case vbIgnore
Resume Next
End Select
Resume EXIT_Close_Click
End Sub
Private Sub Form_Load()
' #VBIDEUtilsERROR#
On Error GoTo ERROR_Form_Load
Me.Height = 4125
Me.Width = 7680
EXIT_Form_Load:
Exit Sub
' #VBIDEUtilsERROR#
ERROR_Form_Load:
Select Case MsgBox("Error " & Err.Number & ": " & Err.Description & vbCrLf & "in Form_Load" & vbCrLf & "The error occured at line: " & Erl, vbAbortRetryIgnore + vbCritical, "Error")
Case vbAbort
Screen.MousePointer = vbDefault
Resume EXIT_Form_Load
Case vbRetry
Resume
Case vbIgnore
Resume Next
End Select
Resume EXIT_Form_Load
End Sub
Private Sub Form_Resize()
On Error Resume Next
Frame1.Move Me.ScaleWidth / 2 - Frame1.Width / 2, Frame1.Top
txtNS.Move txtNS.Left, txtNS.Top, Me.ScaleWidth - 200, Me.ScaleHeight - 1500
End Sub
Private Sub Timer1_Timer()
' #VBIDEUtilsERROR#
On Error GoTo ERROR_Timer1_Timer
If Host.text = "" Then
TraceRT2.Enabled = False
Else
TraceRT2.Enabled = True
End If
EXIT_Timer1_Timer:
Exit Sub
' #VBIDEUtilsERROR#
ERROR_Timer1_Timer:
Select Case MsgBox("Error " & Err.Number & ": " & Err.Description & vbCrLf & "in Timer1_Timer" & vbCrLf & "The error occured at line: " & Erl, vbAbortRetryIgnore + vbCritical, "Error")
Case vbAbort
Screen.MousePointer = vbDefault
Resume EXIT_Timer1_Timer
Case vbRetry
Resume
Case vbIgnore
Resume Next
End Select
Resume EXIT_Timer1_Timer
End Sub
Private Sub TraceRT2_Click()
' #VBIDEUtilsERROR#
On Error GoTo ERROR_TraceRT2_Click
If Me.Host.text = "" Then
MsgBox "Please enter a domain name.", vbCritical
Me.Host.SetFocus
Exit Sub
End If
Me.Label1.Caption = "Please Wait..."
DoEvents
Me.txtNS.text = ""
DoEvents
If Me.Check1.Value = 1 Then
Me.txtNS = ExecCmdPipe("Tracert " & Me.Host.text)
Else
Me.txtNS = ExecCmdPipe("Tracert " & Me.Host.text & " -d")
End If
EXIT_TraceRT2_Click:
Exit Sub
' #VBIDEUtilsERROR#
ERROR_TraceRT2_Click:
Select Case MsgBox("Error " & Err.Number & ": " & Err.Description & vbCrLf & "in TraceRT2_Click" & vbCrLf & "The error occured at line: " & Erl, vbAbortRetryIgnore + vbCritical, "Error")
Case vbAbort
Screen.MousePointer = vbDefault
Resume EXIT_TraceRT2_Click
Case vbRetry
Resume
Case vbIgnore
Resume Next
End Select
Resume EXIT_TraceRT2_Click
End Sub