Click here to Skip to main content
15,880,651 members
Articles / Programming Languages / C#
Article

NetCalculator

Rate me:
Please Sign up or sign in to vote.
4.24/5 (25 votes)
21 Jul 2005CPOL4 min read 103.9K   5.6K   43   24
A simple net calculator for use in networking math calculations
Sample image

Introduction

A year ago, I started the CISCO CCNA course in my country, and the first module was about NetWorking Basics. The first lessons were about Networking, etc. until NetworkMath came with all these steps of calculating subnets, max number of hosts and so on. It is not hard after you get the hang of it, it is quite easy, but it takes lots of time to do the calculations so I have made a "calculator".

The Steps

This is the main idea to do the calculations. (You really need to know all steps in order to be able to do something later.)

  1. Binary presentation of data
  2. Bits and bytes
  3. Base 10 number system
  4. Base 2 number system
  5. Converting decimal numbers to 8-bit binary numbers
  6. Converting 8-bit binary numbers to decimal numbers
  7. Four-octet dotted decimal representation of 32-bit binary numbers
  8. Hexadecimal
  9. Boolean or binary logic
  10. IP addresses and network masks

Network Math

So let's skip steps 1-9 because you all need to know what they are about and it is not appropriate to discuss them here.
Now let's take a closer look at step 10 - IP addresses and network masks.

When IP addresses are assigned to computers, some of the bits on the left side of the 32-bit IP number represent a network. The number of bits designated depends on the address class. The bits left over in the 32-bit IP address identify a particular computer on the network. A computer is referred to as a host. The IP address of a computer consists of a network and a host part.

To inform a computer how the 32-bit IP address has been split, a second 32-bit number called a subnetwork mask is used. This mask is a guide that determines how the IP address is interpreted. It indicates how many of the bits are used to identify the network of the computer. The subnetwork mask sequentially fills in the 1s from the left side of the mask. A subnet mask will always be all 1s until the network address is identified and then it will be all 0s to the end of the mask. The bits in the subnet mask that are 0 identify the computer or host.

Sample image

Some examples of subnet masks are as follows:

11111111000000000000000000000000 written in dotted decimal as 255.0.0.0

11111111111111110000000000000000 written in dotted decimal as 255.255.0.0

A boolean AND of the IP address 10.34.23.134 and the subnet mask 255.0.0.0 produces the network address of this host:

00001010.00100010.00010111.10000110 
11111111.00000000.00000000.00000000 
00001010.00000000.00000000.00000000 

The dotted decimal conversion is 10.0.0.0 which is the network portion of the IP address when the 255.0.0.0 mask is used.

This is the main idea very briefly, for a more complex view we learned about.

The mechanics of Subnetting (with the associated steps) are as follows:

  1. Classes of network IP addresses
  2. Introduction to and reason for subnetting
  3. Establishing the subnet mask address
  4. Applying the subnet mask
  5. Subnetting Class A and B networks
  6. Calculating the resident subnetwork through ANDing

Now I will not explain the whole process because it is very long and... boring and... Now if you want this explained in detail with examples and pictures, you can let me know and I will update the article.

The Project

The project is created in .NET 2003 but can easily be ported in 2005. The screenshot is given above, so it is not a big thing.
I first made this project in Java. After searching the Internet for something familiar, I have came up with nothing, until a friend of mine gave me a link to a JNetTool made by Arthur Ventruba. I downloaded the app and added more features, some bugs were fixed and lots more.
So this .NET app is a port of that tool.

The most important class in the project is IPTool.cs. In there, we have all the "tools" that we need to do the calculations.

I have included the source and the binaries.

To Do List

  1. Add, WhoIS, DNS, PING, TRACEROUTE, PortScan tabs
  2. Fix bugs
  3. Copy to clipboard
  4. Whatever comes up...

Conclusion

English is not my native language, so please excuse me for all the mistakes that I have made...
This is my first article here, so it is not perfect; you are free to make suggestions, remarks, etc.
If you need some information or have any questions, please email me...
I hope to write more and better articles here (I have made lots of useless:) tools using .NET that I want to share).

History

  • 21st July, 2005: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer Ipsos Mori
United Kingdom United Kingdom
Now I am a Full stack web developer at Ipsos Mori, dealing with everything web related.

I was a 22 years old student at Computer Science and Mathematics in Romania, Brasov. My first touch with a computer was in 1985 when my father bought a HC80 computer from some guy. Since then computers and programming is my true passion and desire Smile | :)

Comments and Discussions

 
Questionhow can i find maximum number of host? Pin
Hoang Thang Vo1-Mar-16 5:01
Hoang Thang Vo1-Mar-16 5:01 
GeneralVery good code Pin
Mrlooper4-Nov-14 2:27
Mrlooper4-Nov-14 2:27 
SuggestionGreat code Pin
JDougherty8-Oct-12 7:53
JDougherty8-Oct-12 7:53 
QuestionVB 8.0 to VB 10.0 Pin
Marc Christ29-Aug-12 5:19
Marc Christ29-Aug-12 5:19 
AnswerRe: VB 8.0 to VB 10.0 Pin
Micu Radu29-Aug-13 3:50
Micu Radu29-Aug-13 3:50 
GeneralVery nice! Pin
Newrookie21-Jan-10 13:21
Newrookie21-Jan-10 13:21 
GeneralGreat Code Pin
GRRemlin19-Jan-09 10:48
GRRemlin19-Jan-09 10:48 
GeneralRe: Great Code Pin
Micu Radu19-Jan-09 22:34
Micu Radu19-Jan-09 22:34 
GeneralRe: Great Code Pin
GRRemlin20-Jan-09 3:11
GRRemlin20-Jan-09 3:11 
GeneralIt's a beuty Pin
thorssig29-Nov-08 2:43
thorssig29-Nov-08 2:43 
GeneralRe: It's a beuty Pin
Micu Radu1-Dec-08 3:24
Micu Radu1-Dec-08 3:24 
GeneralA far far way Pin
Andre Fernandes Luiz9-Nov-06 2:44
Andre Fernandes Luiz9-Nov-06 2:44 
GeneralRe: A far far way Pin
Micu Radu13-Nov-06 21:18
Micu Radu13-Nov-06 21:18 
QuestionSubnet from IPAddress and Subnet Mask? Pin
yarborg5-Oct-06 3:52
yarborg5-Oct-06 3:52 
AnswerRe: Subnet from IPAddress and Subnet Mask? Pin
Micu Radu5-Oct-06 4:39
Micu Radu5-Oct-06 4:39 
You can't get the subnet only by using the IP you need them both,
so through code I have calculated the subnet using the IP and SubNetMask...

I don't belive is a direct way to do this...

"Tow things are infinite,
the Universe and human stupidity,
and I am not so sure about the former!"
Albert Einstein

GeneralRe: Subnet from IPAddress and Subnet Mask? Pin
yarborg5-Oct-06 4:44
yarborg5-Oct-06 4:44 
Generalcode usage Pin
Joseph Wee21-Aug-06 21:04
Joseph Wee21-Aug-06 21:04 
AnswerRe: code usage Pin
Micu Radu21-Aug-06 21:45
Micu Radu21-Aug-06 21:45 
GeneralIP Management Pin
drkfiber23-May-06 2:02
drkfiber23-May-06 2:02 
GeneralThank You Pin
drkfiber18-May-06 11:44
drkfiber18-May-06 11:44 
GeneralRe: Thank You Pin
Micu Radu22-May-06 2:14
Micu Radu22-May-06 2:14 
GeneralCode details pls Pin
soniq7722-Jul-05 8:40
soniq7722-Jul-05 8:40 
GeneralRe: Code details pls Pin
Micu Radu23-Jul-05 22:23
Micu Radu23-Jul-05 22:23 
GeneralRe: Code details pls Pin
soniq7724-Jul-05 8:15
soniq7724-Jul-05 8:15 

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.