Click here to Skip to main content
15,880,469 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Communication Library Files - NetTools | Network Population

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
15 Apr 2015GPL34 min read 11K   135   5   1
Populating NICs, online (IP and MAC) and offline IPs in a network environment

Introduction

This example shows how to use the NetTools part of the communication library that a colleague and myself made for demonstration purposes on SICK A.G. Lidar devices (F.i. LMS5xx).

The total library itself enables the user to generate a 3D on screen Lidar image within 15 lines of code (without error handling, etc.). The total library will be posted on a general download page for easy maintenance.

This tip will handle the NetTools NetPopulation part of the library showing a simple way to get your network information. The tools show you which NICs your PC has (IP address, MAC address, connection speed, DHCP enabled (bool), on/off, etc.). It also shows you what IP-address (that matches the subnet of your NICs, so are TCP connectable) your network has and what the MAC addresses of these IPs are.

Why am I posting this? My goal is to create an easy, open platform for Lidar devices as they are more commonly used. If you see anything that should be different, feel free to change the source code and post the result as comment.

Background

As mentioned, this tip only describes part of the total communication library (green block) which in its turn is partSICKlib of a bigger framework (all blocks together) of libraries I internally use to demonstrate Lidar devices. The library is used for approximately 2 years now and works perfectly for our demos and field tests.

All the smaller individual parts can be used to convert SICK Lidar data into 3D pointclouds, LAS, CSV, bitmap or 3D pointclouds with the least of effort giving you the power to generate awesome pointclouddata, 3D representation or bitmaps out of these devices.

This example shows you how to find devices in a network that are connectable. The ideal bonus on this part is that from the online IPs the MAC-addresses are resolved using ARP (basically this class asynchronous pings all possible IPs, checks whether they return information and then checks the ARP-table of the PC to find out the MAC-address). Also, the tool retrieves your network card information hassle free.

In my other tips, I will describe the use of the Serial and TCP part of the library. Later on, these connections will be used to retrieve the LIDAR data and convert it to something useful.

Using the Code

The attached example is made up of smaller pieces, the example retrieves your network card information and checks the online and offline IPs. All is done just by instantiating the class itself (which will start a multithreaded process in the background) and monitor its process:

VB.NET
Public Mynetwork As SICK_Communication.NetTools.NetPopulation

Public Sub Populate()
       
        'Instantiate the class (which will start the population process
        Mynetwork = New SICK_Communication.NetTools.NetPopulation

        'Wait for it to finish
        Do While Mynetwork.Busy = True
            Me.Text = String.Format("Probing network {0}% complete", Mynetwork.PercentCompleted)
            Application.DoEvents()
        Loop

       'Add the found info to the form's text property
        Me.Text = String.Format("Done - {0} online | {1} Offline", _
		Mynetwork.OnlineIPs.Count, Mynetwork.OfflineIPs.Count)
    End Sub

Once the class is done populating, read out all the found information.

Example of a listbox that will be filled with the Network Card information:

VB.NET
Public Sub NICtoList()

    'Get all the IPv4 capable and online adapters from the PC
    Dim MyNics() As SICK_Communication.Ethernet.NICinfo = Mynetwork.MyNICs

    'Clear the listbox
    ListBox1.Items.Clear()

    'Add each Adapter found to the listbox
    For Each Adapter As SICK_Communication.Ethernet.NICinfo In MyNics
        ListBox1.Items.Add(String.Format("{0} : {1} :{2} (status {3})", _
    Adapter.MACaddress, Adapter.IPaddress, Adapter.Adaptername, Adapter.AdapterActive))
    Next
End Sub

Adding the Online IPs info (IP-address and MAC address) to a listbox:

VB.NET
Public Sub OnlineToList()

    'Clear the listbox
    ListBox2.Items.Clear()

    'Add all the items
    For Each ST As SICK_Work.SICK_NetTools.NetInfo In Mynetwork.OnlineIPClass
        ListBox2.Items.Add(String.Format("{0} : {1}", ST.IPaddress, ST.MACaddress))
    Next

End Sub

To have easy sorting, I decided to change the MAC-address for the target devices to our company name instead our full MAC-range. This will make it easier to find these specific devices (you don't need to know the MAC range for the LIDAR devices).

And the offline IP-address (which is only string as nothing is connected and no further information is available).

VB.NET
Public Sub OffLineToList()

    'Clear listbox
    ListBox3.Items.Clear()

    'Add offline ip's
    For Each ST As String In Mynetwork.OfflineIPs
        ListBox3.Items.Add(ST)
    Next

End Sub

Screenshot of the example code is as shown below:

Image 2

Points of Interest

In the communication class, there is a reference to the structure library SICK_Work. This library is just a bunch of classes with little functionality, but they form the pillar for a complete application (as the illustration shows). Because of this library, it's possible to use each library as an individual part as the interconnection between those libraries is not implemented within that same library itself. The reference files are a pre-build library distribution which are needed for the example to be build.

The idea of this class was to make finding devices easier. Although now a days, I'm not using it much, I still think it's worth posting.

Note that IP addresses 255 and 0 are not checked as these are primarily broadcast addresses and not suitable for use (in case you haven't noticed that the example code finds 31 online and 222 offline (together 253 instead of 255) IP addresses)

Remember to share!!

History

The program itself is licensed as GPL software. Some examples were picked from the internet. If I accidentally used anything without permission or overlooked anything, please let me know and I'll correct my errors.

So far, this is the latest adaptation to the library by myself and my colleague referred to as the V4-library. Improvements are always welcome, hope you enjoy using it.

Other Tips

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Help desk / Support
Netherlands Netherlands
Working at a help desk for more then 10 years now, last few years being more into programming examples for industrial sensors and camera's. Expertise Vision sensors and camera's, last two years trying to explore the possibilities of laser scanning devices in industrial applications.

Comments and Discussions

 
QuestionLibrary location Pin
petercaron25-Jan-16 3:53
petercaron25-Jan-16 3:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.