1: Imports System
2: Imports SnmpSharpNet
3: Public Class Form1
4: Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
5: 'check if keyed fields contain numeric only data,stop if they don't
6: If Not IsNumeric(Me.tb_f_o1.Text) Then Exit Sub
7: If Not IsNumeric(Me.tb_f_o2.Text) Then Exit Sub
8: If Not IsNumeric(Me.tb_f_o3.Text) Then Exit Sub
9: If Not IsNumeric(Me.tb_f_o4.Text) Then Exit Sub
10: If Not IsNumeric(Me.tb_t_o1.Text) Then Exit Sub
11: If Not IsNumeric(Me.tb_t_o2.Text) Then Exit Sub
12: If Not IsNumeric(Me.tb_t_o3.Text) Then Exit Sub
13: If Not IsNumeric(Me.tb_t_o4.Text) Then Exit Sub
14: tb_results.Text += "start" & vbCrLf
15: 'convert text box values to integers
16: Dim a_to As Integer = CInt(Me.tb_t_o1.Text)
17: Dim a_from As Integer = CInt(Me.tb_f_o1.Text)
18: Dim b_to As Integer = CInt(Me.tb_t_o2.Text)
19: Dim b_from As Integer = CInt(Me.tb_f_o2.Text)
20: Dim c_to As Integer = CInt(Me.tb_t_o3.Text)
21: Dim c_from As Integer = CInt(Me.tb_f_o3.Text)
22: Dim d_to As Integer = CInt(Me.tb_t_o4.Text)
23: Dim d_from As Integer = CInt(Me.tb_f_o4.Text)
24: ' Use Parse() to convert from the integers to an IPAddress.
25: Dim fromAddress As System.Net.IPAddress = System.Net.IPAddress.Parse(a_from & "." & b_from & "." & c_from & "." & d_from)
26: Dim toAddress As System.Net.IPAddress = System.Net.IPAddress.Parse(a_to & "." & b_to & "." & c_to & "." & d_to)
27: ' We need the integral value of the IP. The Address property is deprecated. Use GetAddressBytes() and
28: ' convert the bytes to a value. If you are using IPv4, this should be 4 bytes, 32 bits, only Integer is needed.
29: Dim currentAddress As System.Net.IPAddress
30: Dim addressBytes() As Byte = fromAddress.GetAddressBytes()
31: Dim addressValue As Integer = BitConverter.ToInt32(addressBytes, 0)
32: Dim toaddressBytes() As Byte = toAddress.GetAddressBytes()
33: Dim toaddressValue As Integer = BitConverter.ToInt32(toaddressBytes, 0)
34: ' The bytes come out in network order; we don't want to figure out if that's backwards or not. Use this method
35: ' to convert to whatever the host machine uses.
36: addressValue = System.Net.IPAddress.NetworkToHostOrder(addressValue)
37: toaddressValue = System.Net.IPAddress.NetworkToHostOrder(toaddressValue)
38: For i = addressValue To toaddressValue
39: Dim thei As Integer = i
40: Dim theb() As Byte
41: ' We're ready to go back to bytes; convert the number back to network order
42: thei = System.Net.IPAddress.HostToNetworkOrder(thei)
43: ' Turn it back into bytes, create the new IP
44: theb = BitConverter.GetBytes(thei)
45: currentAddress = New System.Net.IPAddress(theb)
46: Dim thehostname As String
47: Try
48: thehostname = System.Net.Dns.GetHostEntry(currentAddress.ToString).HostName.ToString
49: Catch ex As Exception
50: thehostname = "Could not detect hostname"
51: End Try
52: tb_results.Text += " IP: " & currentAddress.ToString & " | Active: " & pinger(currentAddress.ToString) & " | Hostname: " & thehostname & vbCrLf
53: My.Application.DoEvents()
54: Next
55: tb_results.Text += "done" & vbCrLf
56: End Sub
57: Function pinger(ip As String)
58: If My.Computer.Network.Ping(ip) Then
59: Return (1)
60: Else
61: Return (0)
62: End If
63: End Function
Friday, June 8, 2012
Network Scanner
Okay, i have achieved a part of my dreams in coding today. I've always wanted to write nifty little network tools that serve a purpose, today, I have actually written one, well at least the draft of a proof of concept for a larger project.
Two key reference that I used to generate the code was:
http://www.xtremevbtalk.com/showthread.php?t=321718
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment