Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / Visual Basic
Article

IP Address, Port Number, Subnet Mask Submission Form Library

Rate me:
Please Sign up or sign in to vote.
3.42/5 (5 votes)
18 Mar 20034 min read 230.5K   3.1K   60   6
A class library for an easy submission of IP Address, Port Number and Subnet Mask

Sample Image

Introduction

This class library is providing an easy and flexible way to submit ip address, port number and subnet mask. I believe such a submission dialog is needed in many applications - and I hope it can also help you because it provides different dialogs for different needs.

Different dialogs for different needs

  1. IP Submission Dialog
  2. IP Submission + Port Number Dialog
  3. IP Submission + Port Number + Subnet Mask Dialog
  4. IP Submission + Port Number + Subnet Mask + Local network adapters Dialog
Image 2
Image 3
Constructor Call 1: IP Address
Constructor Call 2: IP Address + Port
Image 4
Image 5
Constructor Call 3: IP Address, Port, Subnet Mask
Constructor Call 4: IP Address, Port, Subnet Mask, Local network adapters

Setting up the form

As you can see in the constructor calls below all important text components in the dialog can be named individually.

These Form Components are:

  • Title
  • Information message for user
  • OK Button
  • Cancel Button
  • (and when calling dialog 4. another textfield free for use).

Sample constructor calls:

C#
// Example for 1.)

FrmCommon.FrmIPSubnet i = new FrmCommon.FrmIPSubnet(" IP Address", 
    "Please enter ip address.", "OK", "Cancel", "192.168.0.1");

// Example for 2.)
FrmCommon.FrmIPSubnet i = new FrmCommon.FrmIPSubnet(" IP Address",
    "Please enter ip address and port number.", "OK", "Cancel",
  "192.168.0.1", "55521");

// Example for 3.)
FrmCommon.FrmIPSubnet i = new FrmCommon.FrmIPSubnet(" IP Address",
    "Please enter ip address, port number and subnet mask.", "OK",
  "Cancel", "192.168.0.1", "55521", "255.255.255.0");

// Example for 4.)
FrmCommon.FrmIPSubnet i = new FrmCommon.FrmIPSubnet(" IP Address",<BR>    "Please enter your IP Address and Port number. The subnet mask and " + <BR>    "informations about local adapters are not transferred.",<BR>    "OK", "Cancel",    "192.168.0.1", "55521", "255.255.255.0",<BR>    "In order to connect to client the entered subnet mask must match " + <BR>    "your local one.");<BR>

The arguments used when calling the constructor affect the type and look of the form. For example: if you're calling the form with constructor number one you just expect the ip address to be entered and so - only the GUI components regarding this are shown.

Getting the values

Getting the entered values back is as simple as setting them. Every IP submission dialog has the properties:

  • IPAddress
  • Port
  • SubnetMask

Every property can be used for setting and getting the properties. Because these values are initialized when calling the constructor, setting them shouldn't be important for you (only if you want to change the value afterwards).

The values are set and returned in the form (without quotes):

IPAddress : "192.168.0.1"
Port : "55521"
SubnetMask : "255.255.255.0"

If you are using unallowed values (e.g. letters, numbers of of range) the standard value will be used. Those standard values are:

IPAddress: "192.168.0.1"
Port: "1"
SubnetMask: "255.255.255.0"

Sample form call:

C#
// Example for 3.)


// Initializing variables

string ipAddress;

string port;

string subnetMask;


// Calling form and constructor

FrmCommon.FrmIPSubnet i = new FrmCommon.FrmIPSubnet(" IP Address",
    "Please enter ip address, port number and subnet mask.", "OK",
  "Cancel", "192.168.0.1", "55521", "255.255.255.0");

// Shows the dialog
i.ShowDialog();

// Store the entered values in the local variables
ipAddress = i.IPAddress;
port = i.Port;
subnetMask = i.SubnetMask;<BR>

Internal logic

Of course the form should decide whether or not the entered values are valid. Because its a bit tricky (and you might want to customize the library I provided) - here is the internal logic:

General

The ip address and the subnet mask contain of 4 blocks:
Examples:

Examples:  
 IP:192.168.0.1
 Subnet Mask:255.255.255.0

Conditions for IP Address

1. Value range for block one must be between 1 and 223
2. Value range for blocks two-four must be between 0 and 255

Network classBinaryDecimalSubnet mask
A0xxx xxxx0 ... 127255.0.0.0
B10xx xxxx128 ... 191255.255.0.0
C110x xxxx192 ... 223255.255.255.0
D1110 xxxx224 ... 239- (Multicast addresses)
E1111 xxxx240 ... 255- (Experimental addresses)

Private IP Address range:
10.x.x.x
172.x.x.x
192.168.x.x

Conditions for Subnet Mask

1.Only values 0, 128, 192, 224, 240, 248, 252, 254, 255 are allowed in all blocks
 Example: 255.128.0.0 allowed, 255.17.0.0 not allowed
  
2.Is a block containing a value unequal to 0, all blocks on the left side thereof must have the value 255.
 Example: 255.255.248.0 allowed, 192.255.248.0 not allowed
  
3.Is a block containing a value unequal to 255, all blocks on the right side thereof must have the value 0.
 Example: 224.0.0.0 allowed, 224.0.0.128 not allowed
  
4.In the first block the value 0 is not allowed
 In the fourth block the values 254 and 255 are not allowed
 Example: 0.0.0.0 / 255.255.255.254 / 255.255.255.255 not allowed

The subnet mask will be compared to the ip address. Depending on the first block 'AA' of the ip
address (AA.xx.xx.xx) the subnet mask is subject to restrictions.

0 < AA < 127Subnet mask must contain at least 8 leading one's
 Example: 255.0.0.0 / 255.128.0.0 allowed, 254.0.0.0 / 192.0.0.0 not allowed
  
128 < AA < 191Subnet mask must contain at least 16 leading one's
 Example: 255.255.0.0 / 255.255.224.0 allowed, 255.240.0.0 / 255.0.0.0 not allowed
  
129 < AA < 255Subnet mask must contain at least 24 leading one's
 Example: 255.255.255.0 / 255.255.255.248 allowed, 255.252.0.0 / 255.255.254.0 not allowed

 

History

19. March 2003: Initial Release

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Germany Germany
Experience:
- Java
- C#
- XML, XSL, PHP, ASP, ASP.NET
- Server administration

- ASM, Visual Basic (poor)
- Linux (poor)

If you have any offers, questions, or project ideas please feel free to contact me.

If you experience any bugs in my software, please report them.

Thank you.

Comments and Discussions

 
QuestionWhat is the License of this library source? Pin
hatake_kakashi2-Jul-14 0:54
hatake_kakashi2-Jul-14 0:54 
GeneralSuggestion Pin
zitun11-Jun-07 21:29
zitun11-Jun-07 21:29 
GeneralVideo capturing from camera device Pin
Kirubanandam24-Aug-05 3:55
Kirubanandam24-Aug-05 3:55 
GeneralPrivate Networks Pin
Jim Wiese (aka Spunk)31-Jul-03 11:25
Jim Wiese (aka Spunk)31-Jul-03 11:25 
GeneralRe: Private Networks Pin
shvalbo9-Dec-07 4:26
shvalbo9-Dec-07 4:26 
QuestionWhat? Pin
Heath Stewart24-Jun-03 2:13
protectorHeath Stewart24-Jun-03 2:13 

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.