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.)
- Binary presentation of data
- Bits and bytes
- Base 10 number system
- Base 2 number system
- Converting decimal numbers to 8-bit binary numbers
- Converting 8-bit binary numbers to decimal numbers
- Four-octet dotted decimal representation of 32-bit binary numbers
- Hexadecimal
- Boolean or binary logic
- 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.
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:
- Classes of network IP addresses
- Introduction to and reason for subnetting
- Establishing the subnet mask address
- Applying the subnet mask
- Subnetting Class A and B networks
- 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
- Add, WhoIS, DNS, PING, TRACEROUTE, PortScan tabs
- Fix bugs
- Copy to clipboard
- 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
| You must Sign In to use this message board. |
|
|
 |
|
 |
Thanks for the code, it helped me a lot to understand how all this works. If only it had a way to list ALL IPs in the given range.
I had done it using nested loops, but it's not as efficient as I'd like it to be. I'm sure there's a better way 
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
|
 |
|
 |
That's how I solved it eventually. Not sure if it's "more efficient", but it sure does the trick.
long[] netRange = new long[2]; List ipList = new List();
netRange[0] = getNetworkLong(prefix, ip) + 1; netRange[1] = getBroadCastLong(prefix, ip);
while (netRange[0] < netRange[1]) { ipList.Add(long2String(netRange[0])); netRange[0]++; } return ipList;
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
|
 |
|
 |
I'm glad you like it...
"Tow things are infinite, the Universe and human stupidity, and I am not so sure about the former!" Albert Einstein
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Micu
Your article is very useful for me and for my friends at the university, we are developmenting a software for design, configure and test a network, a software where you can add and remove equipaments, and not make us prisioner to only one brand (cisco,IBM...whatever), so this is the main idea....
It is incredible how the Internet link the people from to another side of the world, and I am writing for this, to let you know your article is helping...
If my project can help you, I would be glad to send you when I finished, or maybe when I have a first version.
I´sm sorry about my mistakes in english....
If you wish here is my msn messeger afernandes_luiz@hotmail.com, I am not sure if you user this in Romenia, maybe another kind of instante messeger.
Thank you very much
By
Andre Fernandes Luiz
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Andre,
I very much apriciate your comment, I am very glad to know that my little app is helping others developers in their work.
I think your ideea is great and I can wait to see it in ation, so please feel free to send it to me when is finished.
Don't worry about your english mine is not so great 
In Romania we use all kind of IMs but the moast used is Yahoo.
Thx again and keep in touch.
Have fun coding...
Best regards Micu Radu
"Tow things are infinite, the Universe and human stupidity, and I am not so sure about the former!" Albert Einstein
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I am sure there is a way to do this but can not find any information on it. I was wondering if you knew how to get the actual subnet of a machine just by using it's IP Address and Subnet Mask. For example:
IP = 114.2.22.181 SubnetMask = 255.255.255.0 would be a subnet of 114.2.22.0
Any code would be appreciated.
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thank you for the quick reply. Actually that is exactly what I need. I need a function where I can pass in the IP Address and Subnet Mask and return the Subnet. Like this:
dim Subnet as string = GetSubnet(IP,SubnetMask)
but I don't have the knowledge to create the function to do the calculations. I would be very appreciative to anyone that can post a function to do this. I can't find anything reliable on the net that does it.
Thanks.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi there,
Thank you for your article. I stumbled across it while looking for a method to get the subnet addresses in a network.
Thought I'll ask you, but could I use part of your iptool library in my commercial project.
Alternatively,its there a way to just get the ip address range of my own network?
Thank you once again
I love codes that just work!!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I have been looking for a library like this for a while now. I am trying to write an IP Management system for my workplace. I am also a C# newbie and this seems like a very good way to learn. Thanks again, Jim
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi, Thx ... I have also writen a "IP Management system" (for personal use) with all the gadgets and stuff and this app was my fisrt try into this...
I will post the appliction here very soon (I hope if u are interested...
Have Fun...
"Tow things are infinite, the Universe and human stupidity, and I am not so sure about the former!" Albert Einstein
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Thanks Micu Waiting for the update
I am a begginner in C# and So finds it a bit difficult to decipher code. Tony
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
|