· 9 years ago · Feb 20, 2017, 03:12 PM
1'Author - Narzan Qarma
2'Get IP 1.0
3'Feel Free to modify this code
4'www.narzan.weebly.com
5
6Imports System.Security
7Imports System.Security.Principal.WindowsIdentity
8Imports System.Net
9
10Imports System.Management
11
12Public Class Form1
13 Inherits System.Windows.Forms.Form
14 Dim hostname As String
15 Dim ipaddress As String
16 Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
17
18 Dim mc As System.Management.ManagementClass
19 Friend WithEvents Label666 As Label
20 Friend WithEvents Label555 As Label
21 Friend WithEvents txtGmail_User As TextBox
22 Friend WithEvents txtGmail_Pass As TextBox
23 Friend WithEvents Label777 As Label
24 Friend WithEvents txtSMTP_Host As TextBox
25 Friend WithEvents Label888 As Label
26 Friend WithEvents txtSMTP_Port As TextBox
27 Friend WithEvents cmdSend As Button
28 Friend WithEvents txtRecip As TextBox
29 Friend WithEvents txtSubj As TextBox
30 Friend WithEvents txtMessage As TextBox
31 Friend WithEvents Label111 As Label
32 Friend WithEvents Label2222 As Label
33 Friend WithEvents Label3333 As Label
34 Friend WithEvents Timer1 As Timer
35 Friend WithEvents Button1 As Button
36 Dim mo As ManagementObject
37
38
39#Region " Windows Form Designer generated code "
40
41 Public Sub New()
42 MyBase.New()
43
44 'This call is required by the Windows Form Designer.
45 InitializeComponent()
46
47 'Add any initialization after the InitializeComponent() call
48
49 End Sub
50
51 'Form overrides dispose to clean up the component list.
52 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
53 If disposing Then
54 If Not (components Is Nothing) Then
55 components.Dispose()
56 End If
57 End If
58 MyBase.Dispose(disposing)
59 End Sub
60
61 'Required by the Windows Form Designer
62 Private components As System.ComponentModel.IContainer
63 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
64 Me.components = New System.ComponentModel.Container()
65 Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
66 Me.Label666 = New System.Windows.Forms.Label()
67 Me.Label555 = New System.Windows.Forms.Label()
68 Me.txtGmail_User = New System.Windows.Forms.TextBox()
69 Me.txtGmail_Pass = New System.Windows.Forms.TextBox()
70 Me.Label777 = New System.Windows.Forms.Label()
71 Me.txtSMTP_Host = New System.Windows.Forms.TextBox()
72 Me.Label888 = New System.Windows.Forms.Label()
73 Me.txtSMTP_Port = New System.Windows.Forms.TextBox()
74 Me.cmdSend = New System.Windows.Forms.Button()
75 Me.txtRecip = New System.Windows.Forms.TextBox()
76 Me.txtSubj = New System.Windows.Forms.TextBox()
77 Me.txtMessage = New System.Windows.Forms.TextBox()
78 Me.Label111 = New System.Windows.Forms.Label()
79 Me.Label2222 = New System.Windows.Forms.Label()
80 Me.Label3333 = New System.Windows.Forms.Label()
81 Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
82 Me.Button1 = New System.Windows.Forms.Button()
83 Me.SuspendLayout()
84 '
85 'Label666
86 '
87 Me.Label666.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Bold)
88 Me.Label666.Location = New System.Drawing.Point(4, 10)
89 Me.Label666.Name = "Label666"
90 Me.Label666.Size = New System.Drawing.Size(106, 18)
91 Me.Label666.TabIndex = 20
92 Me.Label666.Text = "Gmail Username:"
93 Me.Label666.TextAlign = System.Drawing.ContentAlignment.MiddleRight
94 '
95 'Label555
96 '
97 Me.Label555.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Bold)
98 Me.Label555.Location = New System.Drawing.Point(3, 31)
99 Me.Label555.Name = "Label555"
100 Me.Label555.Size = New System.Drawing.Size(71, 20)
101 Me.Label555.TabIndex = 21
102 Me.Label555.Text = "Password:"
103 Me.Label555.TextAlign = System.Drawing.ContentAlignment.MiddleRight
104 '
105 'txtGmail_User
106 '
107 Me.txtGmail_User.BackColor = System.Drawing.SystemColors.InfoText
108 Me.txtGmail_User.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Bold)
109 Me.txtGmail_User.ForeColor = System.Drawing.Color.LimeGreen
110 Me.txtGmail_User.Location = New System.Drawing.Point(112, 9)
111 Me.txtGmail_User.Name = "txtGmail_User"
112 Me.txtGmail_User.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
113 Me.txtGmail_User.Size = New System.Drawing.Size(208, 21)
114 Me.txtGmail_User.TabIndex = 22
115 Me.txtGmail_User.Text = "your_email@gmail.com"
116 '
117 'txtGmail_Pass
118 '
119 Me.txtGmail_Pass.BackColor = System.Drawing.SystemColors.InfoText
120 Me.txtGmail_Pass.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Bold)
121 Me.txtGmail_Pass.ForeColor = System.Drawing.Color.LimeGreen
122 Me.txtGmail_Pass.Location = New System.Drawing.Point(112, 31)
123 Me.txtGmail_Pass.Name = "txtGmail_Pass"
124 Me.txtGmail_Pass.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
125 Me.txtGmail_Pass.Size = New System.Drawing.Size(208, 21)
126 Me.txtGmail_Pass.TabIndex = 23
127 '
128 'Label777
129 '
130 Me.Label777.Enabled = False
131 Me.Label777.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Bold)
132 Me.Label777.Location = New System.Drawing.Point(-5, 56)
133 Me.Label777.Name = "Label777"
134 Me.Label777.Size = New System.Drawing.Size(81, 17)
135 Me.Label777.TabIndex = 24
136 Me.Label777.Text = "SMTP Host:"
137 Me.Label777.TextAlign = System.Drawing.ContentAlignment.MiddleRight
138 '
139 'txtSMTP_Host
140 '
141 Me.txtSMTP_Host.BackColor = System.Drawing.SystemColors.InfoText
142 Me.txtSMTP_Host.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Bold)
143 Me.txtSMTP_Host.ForeColor = System.Drawing.Color.LimeGreen
144 Me.txtSMTP_Host.Location = New System.Drawing.Point(112, 53)
145 Me.txtSMTP_Host.Name = "txtSMTP_Host"
146 Me.txtSMTP_Host.Size = New System.Drawing.Size(208, 21)
147 Me.txtSMTP_Host.TabIndex = 25
148 Me.txtSMTP_Host.Text = "smtp.gmail.com"
149 '
150 'Label888
151 '
152 Me.Label888.Enabled = False
153 Me.Label888.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Bold)
154 Me.Label888.Location = New System.Drawing.Point(-9, 77)
155 Me.Label888.Name = "Label888"
156 Me.Label888.Size = New System.Drawing.Size(83, 21)
157 Me.Label888.TabIndex = 26
158 Me.Label888.Text = "SMTP Port:"
159 Me.Label888.TextAlign = System.Drawing.ContentAlignment.MiddleRight
160 '
161 'txtSMTP_Port
162 '
163 Me.txtSMTP_Port.BackColor = System.Drawing.SystemColors.InfoText
164 Me.txtSMTP_Port.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Bold)
165 Me.txtSMTP_Port.ForeColor = System.Drawing.Color.LimeGreen
166 Me.txtSMTP_Port.Location = New System.Drawing.Point(112, 75)
167 Me.txtSMTP_Port.Name = "txtSMTP_Port"
168 Me.txtSMTP_Port.Size = New System.Drawing.Size(208, 21)
169 Me.txtSMTP_Port.TabIndex = 27
170 Me.txtSMTP_Port.Text = "587"
171 '
172 'cmdSend
173 '
174 Me.cmdSend.Location = New System.Drawing.Point(221, 200)
175 Me.cmdSend.Name = "cmdSend"
176 Me.cmdSend.Size = New System.Drawing.Size(99, 24)
177 Me.cmdSend.TabIndex = 28
178 Me.cmdSend.Text = "Send Test"
179 Me.cmdSend.UseVisualStyleBackColor = True
180 '
181 'txtRecip
182 '
183 Me.txtRecip.Location = New System.Drawing.Point(112, 101)
184 Me.txtRecip.Name = "txtRecip"
185 Me.txtRecip.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
186 Me.txtRecip.Size = New System.Drawing.Size(208, 20)
187 Me.txtRecip.TabIndex = 29
188 '
189 'txtSubj
190 '
191 Me.txtSubj.Location = New System.Drawing.Point(112, 122)
192 Me.txtSubj.Name = "txtSubj"
193 Me.txtSubj.Size = New System.Drawing.Size(208, 20)
194 Me.txtSubj.TabIndex = 30
195 Me.txtSubj.Text = "Tracking USB IP"
196 '
197 'txtMessage
198 '
199 Me.txtMessage.Location = New System.Drawing.Point(112, 143)
200 Me.txtMessage.Multiline = True
201 Me.txtMessage.Name = "txtMessage"
202 Me.txtMessage.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
203 Me.txtMessage.Size = New System.Drawing.Size(208, 51)
204 Me.txtMessage.TabIndex = 31
205 '
206 'Label111
207 '
208 Me.Label111.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Bold)
209 Me.Label111.Location = New System.Drawing.Point(-7, 104)
210 Me.Label111.Name = "Label111"
211 Me.Label111.Size = New System.Drawing.Size(35, 13)
212 Me.Label111.TabIndex = 32
213 Me.Label111.Text = "To:"
214 Me.Label111.TextAlign = System.Drawing.ContentAlignment.MiddleRight
215 '
216 'Label2222
217 '
218 Me.Label2222.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Bold)
219 Me.Label2222.Location = New System.Drawing.Point(-5, 123)
220 Me.Label2222.Name = "Label2222"
221 Me.Label2222.Size = New System.Drawing.Size(62, 17)
222 Me.Label2222.TabIndex = 33
223 Me.Label2222.Text = "Subject:"
224 Me.Label2222.TextAlign = System.Drawing.ContentAlignment.MiddleRight
225 '
226 'Label3333
227 '
228 Me.Label3333.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Bold)
229 Me.Label3333.Location = New System.Drawing.Point(5, 143)
230 Me.Label3333.Name = "Label3333"
231 Me.Label3333.Size = New System.Drawing.Size(62, 19)
232 Me.Label3333.TabIndex = 34
233 Me.Label3333.Text = "Message:"
234 Me.Label3333.TextAlign = System.Drawing.ContentAlignment.MiddleRight
235 '
236 'Timer1
237 '
238 Me.Timer1.Enabled = True
239 Me.Timer1.Interval = 1
240 '
241 'Button1
242 '
243 Me.Button1.Location = New System.Drawing.Point(112, 200)
244 Me.Button1.Name = "Button1"
245 Me.Button1.Size = New System.Drawing.Size(99, 24)
246 Me.Button1.TabIndex = 35
247 Me.Button1.Text = "Save"
248 Me.Button1.UseVisualStyleBackColor = True
249 '
250 'Form1
251 '
252 Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
253 Me.ClientSize = New System.Drawing.Size(328, 231)
254 Me.Controls.Add(Me.Button1)
255 Me.Controls.Add(Me.txtSubj)
256 Me.Controls.Add(Me.txtRecip)
257 Me.Controls.Add(Me.cmdSend)
258 Me.Controls.Add(Me.txtSMTP_Port)
259 Me.Controls.Add(Me.txtSMTP_Host)
260 Me.Controls.Add(Me.txtGmail_Pass)
261 Me.Controls.Add(Me.txtGmail_User)
262 Me.Controls.Add(Me.Label555)
263 Me.Controls.Add(Me.Label777)
264 Me.Controls.Add(Me.Label666)
265 Me.Controls.Add(Me.Label3333)
266 Me.Controls.Add(Me.Label2222)
267 Me.Controls.Add(Me.Label111)
268 Me.Controls.Add(Me.Label888)
269 Me.Controls.Add(Me.txtMessage)
270 Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
271 Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
272 Me.MaximizeBox = False
273 Me.Name = "Form1"
274 Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
275 Me.Text = "IP Sender"
276 Me.ResumeLayout(False)
277 Me.PerformLayout()
278
279 End Sub
280
281#End Region
282
283 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
284
285 End Sub
286
287
288 Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
289 Me.Dispose(True)
290
291 End Sub
292
293 Private Sub txtSMTP_Port_TextChanged(sender As Object, e As EventArgs) Handles txtSMTP_Port.TextChanged
294
295 End Sub
296
297 Private Sub cmdSend_Click(sender As Object, e As EventArgs) Handles cmdSend.Click
298 Call disControl() 'Disable all controls
299 'Call the sendemail procedure
300 Call sendEmail(Me.txtRecip.Text.Trim, Me.txtSubj.Text.Trim, Me.txtMessage.Text.Trim, Me.txtGmail_User.Text.Trim,
301 Me.txtGmail_Pass.Text.Trim, Me.txtSMTP_Host.Text.Trim, CInt(Me.txtSMTP_Port.Text.Trim))
302 Call enaControl() 'Enable all controls after sending
303 End Sub
304
305 Private Sub txtGmail_User_TextChanged(sender As Object, e As EventArgs) Handles txtGmail_User.TextChanged
306
307 End Sub
308
309 Private Function invalidSendEntry() As Boolean
310 'Check if all fields have values
311 If Me.txtMessage.Text.Trim = "" Or Me.txtRecip.Text.Trim = "" Or Me.txtSubj.Text.Trim = "" Or
312 Me.txtGmail_Pass.Text.Trim = "" Or Me.txtGmail_User.Text.Trim = "" Then
313 MsgBox("All fields are required!", MsgBoxStyle.Exclamation, "Insufficient Data")
314 Return True
315 End If
316 'Check if email is valid
317 If Not Me.txtRecip.Text Like "*@*" Or Not Me.txtRecip.Text Like "*.*" Then
318 MsgBox("Recipient is not valid!", MsgBoxStyle.Exclamation, "Not valid address")
319 Return True
320 End If
321 'Check if from address is valid
322 If Not Me.txtGmail_User.Text.Trim.ToLower Like "*@gmail.com" Then
323 MsgBox("Invalid from address. Please include @gmail.com", MsgBoxStyle.Exclamation, "Invalid from address")
324 Return True
325 End If
326 End Function
327
328
329 Private Sub disControl()
330 Me.txtRecip.Enabled = False
331 Me.txtSubj.Enabled = False
332 Me.txtMessage.Enabled = False
333
334 Me.cmdSend.Enabled = False
335 End Sub
336
337 Private Sub enaControl()
338 Me.txtRecip.Enabled = True
339 Me.txtSubj.Enabled = True
340 Me.txtMessage.Enabled = True
341
342 Me.cmdSend.Enabled = True
343 End Sub
344
345 Private Sub txtRecip_TextChanged(sender As Object, e As EventArgs) Handles txtRecip.TextChanged
346
347 End Sub
348
349 Private Sub txtMessage_TextChanged(sender As Object, e As EventArgs) Handles txtMessage.TextChanged
350
351 End Sub
352
353 Private Sub Label7_Click(sender As Object, e As EventArgs)
354
355 End Sub
356
357 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
358
359
360
361 Dim wc As New WebClient
362
363 ipaddress = (CType(h.AddressList.GetValue(0), IPAddress).ToString)
364 hostname = Dns.GetHostName()
365
366 txtMessage.Text = wc.DownloadString("http://icanhazip.com/") & Environment.NewLine & ipaddress & Environment.NewLine & hostname & Environment.NewLine
367
368 mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
369 Dim moc As ManagementObjectCollection = mc.GetInstances()
370
371 Timer1.Stop()
372
373 Call disControl() 'Disable all controls
374 'Call the sendemail procedure
375 Call sendEmail(Me.txtRecip.Text.Trim, Me.txtSubj.Text.Trim, Me.txtMessage.Text.Trim, Me.txtGmail_User.Text.Trim,
376 Me.txtGmail_Pass.Text.Trim, Me.txtSMTP_Host.Text.Trim, CInt(Me.txtSMTP_Port.Text.Trim))
377 Call enaControl() 'Enable all controls after sending
378
379 Timer1.Stop()
380
381
382 End Sub
383
384 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
385 txtGmail_User.Text = My.Settings.ST
386 txtGmail_Pass.Text = My.Settings.SP
387 txtRecip.Text = My.Settings.STO
388
389 End Sub
390
391 Private Sub Button1_Click_2(sender As Object, e As EventArgs) Handles Button1.Click
392 My.Settings.ST = txtGmail_User.Text
393 My.Settings.SP = txtGmail_Pass.Text
394 My.Settings.STO = txtRecip.Text
395
396 My.Settings.Save()
397 End Sub
398
399 Private Sub txtGmail_Pass_TextChanged(sender As Object, e As EventArgs) Handles txtGmail_Pass.TextChanged
400
401 End Sub
402
403
404End Class