Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / Win32

Communication Library Files - NetTools | IsSameSubnet

0.00/5 (No votes)
15 Apr 2015GPL32 min read 8.7K   64  
Communication Library Files - NetTools | IsSameSubnet

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.)

This tip will handle the NetTools IsSameSubnet part of the library showing a simple way to test if two IPs and subnetmask are able to connect on a TCP level.

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 part SICKlibof a bigger framework (all blocks together) of libraries I internally use to demonstrate Lidar devices. The library has been 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 amount of effort giving you the power to generate awesome pointclouddata, 3D representation or bitmaps out of these devices.

This example shows you how to use the same IsSameSubnet function from the NetTools class of the communication library.

Why create this? Because a normal 255.255.255.0 subnetmask is pretty straight forward but sometimes, just sometimes, an admin of a network will have weird combos and the question "can I connect to this device?" isn't that easy. Of course, manually things can be calculated but this function just makes life easier, and that's just why it exists.

Using the Code

The function itself returns a boolean value if two IP addresses and subnets are interconnectable yes or no. Inputted are an IPaddress and subnet for both the master and the slave:

VB.NET
If SICK_Communication.NetTools.IsSameSubnet(IP1, Subnet1, IP2, Subnet2) = True Then
           Label5.Text = "IP's are TCP connectable"
           Label5.ForeColor = Color.LimeGreen
       Else
           Label5.Text = "IP's are NOT TCP connectable"
           Label5.ForeColor = Color.Red
       End If

That's it.

The example shows you how to use this and check whether a string classifies as an IP-address and how to parse them through the function (which is basically the code above):

Image 2

Points of Interest

The reference files are a pre-build set of the library required to get the whole thing build.

Just 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)