Click here to Skip to main content
Click here to Skip to main content
Go to top

IP Address, Port Number, Subnet Mask Submission Form Library

, 18 Mar 2003
Rate this:
Please Sign up or sign in to vote.
A class library for an easy submission of IP Address, Port Number and Subnet Mask

Sample Image

<!------------------------------- STEP 3 ---------------------------><!-- Add the article text. Please use simple formatting (

,

etc) -->

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


Constructor Call 1: IP Address
Constructor Call 2: IP Address + Port
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:

// 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:

// 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 class Binary Decimal Subnet mask
A 0xxx xxxx 0 ... 127 255.0.0.0
B 10xx xxxx 128 ... 191 255.255.0.0
C 110x xxxx 192 ... 223 255.255.255.0
D 1110 xxxx 224 ... 239 - (Multicast addresses)
E 1111 xxxx 240 ... 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 < 127 Subnet 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 < 191 Subnet 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 < 255 Subnet 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

Share

About the Author

Christian Ballerstaller
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? Pinmemberhatake_kakashi2-Jul-14 0:54 
GeneralSuggestion Pinmemberzitun11-Jun-07 21:29 
GeneralVideo capturing from camera device PinmemberKirubanandam24-Aug-05 3:55 
GeneralPrivate Networks PinmemberSpunk31-Jul-03 11:25 
GeneralRe: Private Networks Pinmembershvalbo9-Dec-07 4:26 
QuestionWhat? PineditorHeath Stewart24-Jun-03 2:13 
What is this submitting? It's merely gathering information and displaying it, it seems.
 
Also, you should read the naming guidelines in the .NET Framework SDK. The polish notation is dead and was / should never be used for publicly accessible classes, methods, properties, fields, etc. Using a somewhat similar naming convention within a scope (such as an API or framework) is important for the whole community and you'll never see this in a commercial or reputable application or library.
 

Reminiscent of my younger years...
10 LOAD "SCISSORS"
20 RUN

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 19 Mar 2003
Article Copyright 2003 by Christian Ballerstaller
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid