-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pulihora Packet.vb
278 lines (251 loc) · 10.7 KB
/
Pulihora Packet.vb
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
Option Strict Off
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListView1 As System.Windows.Forms.ListView
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents AxPacketXCtrl1 As AxPacketXLib.AxPacketXCtrl
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
Me.ListView1 = New System.Windows.Forms.ListView
Me.AxPacketXCtrl1 = New AxPacketXLib.AxPacketXCtrl
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.Label1 = New System.Windows.Forms.Label
CType(Me.AxPacketXCtrl1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'ListView1
'
Me.ListView1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.ListView1.FullRowSelect = True
Me.ListView1.GridLines = True
Me.ListView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable
Me.ListView1.Location = New System.Drawing.Point(0, 27)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(722, 205)
Me.ListView1.TabIndex = 1
Me.ListView1.UseCompatibleStateImageBehavior = False
Me.ListView1.View = System.Windows.Forms.View.Details
'
'AxPacketXCtrl1
'
Me.AxPacketXCtrl1.Enabled = True
Me.AxPacketXCtrl1.Location = New System.Drawing.Point(112, 32)
Me.AxPacketXCtrl1.Name = "AxPacketXCtrl1"
Me.AxPacketXCtrl1.OcxState = CType(resources.GetObject("AxPacketXCtrl1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxPacketXCtrl1.Size = New System.Drawing.Size(192, 192)
Me.AxPacketXCtrl1.TabIndex = 2
Me.AxPacketXCtrl1.Visible = False
'
'Button2
'
Me.Button2.Enabled = False
Me.Button2.Location = New System.Drawing.Point(301, 1)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(75, 23)
Me.Button2.TabIndex = 5
Me.Button2.Text = "Start"
Me.Button2.UseVisualStyleBackColor = True
'
'Button3
'
Me.Button3.Enabled = False
Me.Button3.Location = New System.Drawing.Point(382, 1)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(75, 23)
Me.Button3.TabIndex = 6
Me.Button3.Text = "Stop"
Me.Button3.UseVisualStyleBackColor = True
'
'ComboBox1
'
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.FormattingEnabled = True
Me.ComboBox1.Location = New System.Drawing.Point(12, 3)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(283, 21)
Me.ComboBox1.TabIndex = 7
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(464, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(62, 13)
Me.Label1.TabIndex = 8
Me.Label1.Text = "Syn Count :"
'
'Form1
'
Me.ClientSize = New System.Drawing.Size(722, 233)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.AxPacketXCtrl1)
Me.Controls.Add(Me.ListView1)
Me.Name = "Form1"
Me.Text = "Pulihora Packet"
CType(Me.AxPacketXCtrl1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
Dim i As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Add columns to list view
ListView1.Columns().Add("No.", 100, HorizontalAlignment.Left)
ListView1.Columns().Add("Date", 100, HorizontalAlignment.Left)
ListView1.Columns().Add("Protocol", 100, HorizontalAlignment.Left)
ListView1.Columns().Add("Src IP", 100, HorizontalAlignment.Left)
ListView1.Columns().Add("Dest IP", 100, HorizontalAlignment.Left)
ListView1.Columns().Add("Syn Flag", 100, HorizontalAlignment.Left)
ListView1.Columns().Add("IP id", 100, HorizontalAlignment.Left)
'Refresh adapters collection
AxPacketXCtrl1.Reset()
'Display the default adapter
For i = 1 To AxPacketXCtrl1.Adapters.Count
ComboBox1.Items.Add(AxPacketXCtrl1.Adapters(i).Description)
Next
'MsgBox(AxPacketXCtrl1.Adapter.Description)
'Enable menu items
CaptureStop = False
CaptureStart = True
End Sub
Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Stop the running capture
If CaptureStop = True Then
AxPacketXCtrl1.Stop()
End If
End Sub
Private Sub FileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End
End Sub
Private oPacketColl As New PacketXLib.PacketCollectionClass
Dim vnCounter As Integer
Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
'Display packet data
If ListView1.SelectedItems.Count > 0 Then
Dim oPacket As PacketXLib.Packet
oPacket = oPacketColl(ListView1.SelectedIndices().Item(0) + 1)
Dim vByte As Byte
Dim sData As String
Dim nPosition, nColumns As Integer
nColumns = 16
For Each vByte In oPacket.DataArray
If nPosition = 8 Then
sData = sData + " "
End If
If nPosition >= nColumns Then
sData = sData + vbCrLf : nPosition = 1
Else
nPosition = nPosition + 1
End If
If vByte <= &HF Then
sData = sData + "0"
End If
sData = sData + Hex(vByte) + " "
Next
MsgBox(sData, MsgBoxStyle.Information, "Packet Detail")
End If
End Sub
Private Sub AxPacketXCtrl1_OnPacket(ByVal sender As Object, ByVal e As AxPacketXLib._IPktXPacketXCtrlEvents_OnPacketEvent) Handles AxPacketXCtrl1.OnPacket
'Display packet date and size
Dim I As Short
Dim thisPacket As String
Dim SourceIP As String = ""
Dim DestIP As String = ""
Dim prtcl As String = ""
Dim Ipid As String = e.pPacket.Data(19).ToString("X") & "," & e.pPacket.Data(20).ToString("X")
If e.pPacket.Data(14) = 69 And e.pPacket.Data(23) = 6 Then
SourceIP = e.pPacket.Data(26) & "." & _
e.pPacket.Data(27) & "." & + _
e.pPacket.Data(28) & "." & + _
e.pPacket.Data(29)
DestIP = e.pPacket.Data(30) & "." & _
e.pPacket.Data(31) & "." & + _
e.pPacket.Data(32) & "." & + _
e.pPacket.Data(33)
thisPacket = ""
For I = 0 To e.pPacket.DataSize - 1
thisPacket = thisPacket & Chr(e.pPacket.Data(I))
Next
If e.pPacket.Protocol = PacketXLib.PktXProtocolType.PktXProtocolTypeTCP Then
prtcl = "TCP"
End If
If e.pPacket.Protocol = PacketXLib.PktXProtocolType.PktXProtocolTypeUDP Then
prtcl = "UDP"
End If
If e.pPacket.Protocol = PacketXLib.PktXProtocolType.PktXProtocolTypeIP Then
prtcl = "IP"
End If
Dim aItem As New ListViewItem(CStr(vnCounter))
aItem.SubItems().Add(CStr(e.pPacket.Date))
aItem.SubItems().Add(prtcl)
aItem.SubItems().Add(SourceIP)
aItem.SubItems().Add(DestIP)
aItem.SubItems().Add("1")
aItem.SubItems().Add(Ipid)
ListView1.Items().Add(aItem)
'Save packet
oPacketColl.Add(e.pPacket)
vnCounter += 1
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Dim CaptureStart, CaptureStop As Boolean
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Clear list view
ListView1.Items().Clear()
'Clear packet collection
oPacketColl.RemoveAll()
vnCounter = 0
'Start capture
AxPacketXCtrl1.Adapter.BPFilter = "tcp[13] & (0x02|0x04) != 0"
AxPacketXCtrl1.Start()
CaptureStart = False
CaptureStop = True
Button3.Enabled = True
Button2.Enabled = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'Stop capture
AxPacketXCtrl1.Stop()
CaptureStart = True
CaptureStop = False
Button2.Enabled = True
Button3.Enabled = False
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
AxPacketXCtrl1.Adapter = AxPacketXCtrl1.Adapters(ComboBox1.SelectedIndex + 1)
Button2.Enabled = True
End Sub
End Class