Click here to Skip to main content
13,454,124 members (48,008 online)
Click here to Skip to main content
Add your own
alternative version


60 bookmarked
Posted 18 Mar 2003

IP Address, Port Number, Subnet Mask Submission Form Library

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


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", "");

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

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

// 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",    "", "55521", "",<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 : ""
Port : "55521"
SubnetMask : ""

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

IPAddress: ""
Port: "1"
SubnetMask: ""

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", "", "55521", "");

// Shows the dialog

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


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

 Subnet Mask:

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:

Conditions for Subnet Mask

1.Only values 0, 128, 192, 224, 240, 248, 252, 254, 255 are allowed in all blocks
 Example: allowed, 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: allowed, 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: allowed, 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: / / 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: / allowed, / not allowed
128 < AA < 191Subnet mask must contain at least 16 leading one's
 Example: / allowed, / not allowed
129 < AA < 255Subnet mask must contain at least 24 leading one's
 Example: / allowed, / not allowed



19. March 2003: Initial Release


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


About the Author

Christian Ballerstaller
Web Developer
Germany Germany
- Java
- C#
- 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.

You may also be interested in...


Comments and Discussions

QuestionWhat is the License of this library source? Pin
hatake_kakashi2-Jul-14 0:54
memberhatake_kakashi2-Jul-14 0:54 
GeneralSuggestion Pin
zitun11-Jun-07 21:29
memberzitun11-Jun-07 21:29 
GeneralVideo capturing from camera device Pin
Kirubanandam24-Aug-05 3:55
memberKirubanandam24-Aug-05 3:55 
Respected Sir,

Now i am capturing the video frame from camera device using filters (i.e Source filter and render filter) but it will take the CPU usage 45-60% for only capturing and display.

So can you Please send the program for capturing the video frame from camera device and store the frame into buffer(LPBYTE) using vc++.(not using Directx filters)

Please send the program into following mail ID:
Rose | [Rose]

GeneralPrivate Networks Pin
Spunk31-Jul-03 11:25
memberSpunk31-Jul-03 11:25 
GeneralRe: Private Networks Pin
shvalbo9-Dec-07 4:26
membershvalbo9-Dec-07 4:26 
QuestionWhat? Pin
Heath Stewart24-Jun-03 2:13
editorHeath 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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180321.1 | Last Updated 19 Mar 2003
Article Copyright 2003 by Christian Ballerstaller
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid