Web Images Videos Maps News Groups Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
subnet calculations
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
ohynes  
View profile  
 More options Oct 21 2004, 3:59 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: "ohynes" <shaggy_ohy...@ntlworld.ie>
Date: Thu, 21 Oct 2004 19:59:42 GMT
Local: Thurs, Oct 21 2004 3:59 pm
Subject: subnet calculations
hey newbie here
wondering if there is anyone out there who can help me
im trying to make a c# subnet calulator using the

IPAddress class

i cant seem to figure out how to do all the subnet calculations
now i can do them on paper but thats about it
just starting to learn c sharp

well if any one could help me
it would be great

cheers


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Morten Wennevik  
View profile  
 More options Oct 21 2004, 5:33 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: "Morten Wennevik" <MortenWenne...@hotmail.com>
Date: Thu, 21 Oct 2004 23:33:59 +0200
Local: Thurs, Oct 21 2004 5:33 pm
Subject: Re: subnet calculations
Hi ohynes,

First, do it on paper.
Then write it again as pseudo code along the lines of

if this happens
        do that
otherwise
        don't do that

When you have pseudo code start thinking about what variables you need and  
how to form if sentences etc.
Write your code based on pseudo code.

--
Happy Coding!
Morten Wennevik [C# MVP]


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shaggyh  
View profile  
 More options Oct 21 2004, 6:50 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: "Shaggyh" <shaggy_ohy...@ntlworld.ie>
Date: Thu, 21 Oct 2004 22:50:39 GMT
Local: Thurs, Oct 21 2004 6:50 pm
Subject: Re: subnet calculations
tryed that but dont no enough
to do it.. like AND function
and binary in c#

any other advice?

"Morten Wennevik" <MortenWenne...@hotmail.com> wrote in message

news:opsf8ouxgeklbvpo@pbn_computer...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Morten Wennevik  
View profile  
 More options Oct 22 2004, 2:09 am
Newsgroups: microsoft.public.dotnet.languages.csharp
From: "Morten Wennevik" <MortenWenne...@hotmail.com>
Date: Fri, 22 Oct 2004 08:09:32 +0200
Local: Fri, Oct 22 2004 2:09 am
Subject: Re: subnet calculations
Shaggyh,

Give us some of your pseudo code and we can help you translate it to the  
equivalent C# code.

--
Happy Coding!
Morten Wennevik [C# MVP]


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shaggyh  
View profile  
 More options Oct 22 2004, 6:49 am
Newsgroups: microsoft.public.dotnet.languages.csharp
From: "Shaggyh" <shaggy_ohy...@ntlworld.ie>
Date: Fri, 22 Oct 2004 10:49:14 GMT
Local: Fri, Oct 22 2004 6:49 am
Subject: Re: subnet calculations
ok pseudo code is

variables
IPAddress ipaddress
int networkbits
int borrowedbits

class subnetinfo(string ipaddress, int netbits, int borbits)
{
    this.ipaddress = IPaddress.parse(ipaddress)
    networkbits = netbits
    borrowedbits = borbits

}

class void calsubnet()
{
    this is where i get stuck
    trying to figure out this part
  }

"Morten Wennevik" <MortenWenne...@hotmail.com> wrote in message

news:opsf9cp6t0klbvpo@pbn_computer...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Morten Wennevik  
View profile  
 More options Oct 22 2004, 10:12 am
Newsgroups: microsoft.public.dotnet.languages.csharp
From: "Morten Wennevik" <MortenWenne...@hotmail.com>
Date: Fri, 22 Oct 2004 16:12:52 +0200
Local: Fri, Oct 22 2004 10:12 am
Subject: Re: subnet calculations
Ok Shaggyh,

Are you trying to calculate the subnetmask from the knowledge of an ip  
address or calculate ip addresses based on a given subnet mask?  I don't  
think you can do the former without checking variues ip addresses against  
some dns servers or similar.

If you want to calculate ip addresses based on subnet, what information do  
you have?
Subnet masks are given as xxx.xxx.xxx.xxx.  If you are given a mask and an  
ip address and want to calculate possible ip addresses using that address  
and mask there are several ways to do it.

Internally the subnet mask and ip addresses are treated as four bytes.
168.192.20.44 with a subnet mask of 255.255.255.192 would mean
10101000.11000000.00010100.00101100 for the ip address and
11111111.11111111.11111111.11000000 for the subnet mask meaning
00000000.00000000.00000000.00111111 possible addresses in your range

I'm not the one to ask for calculating ip addresses based on subnet masks  
as I only know the basics like the first and two last addresses in a range  
are reserved (I think).  I can only help you translate your pseudo code  
into C#.

On Fri, 22 Oct 2004 10:49:14 GMT, Shaggyh <shaggy_ohy...@ntlworld.ie>  
wrote:

--
Happy Coding!
Morten Wennevik [C# MVP]

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shaggyh  
View profile  
 More options Oct 22 2004, 6:43 pm
Newsgroups: microsoft.public.dotnet.languages.csharp
From: "Shaggyh" <shaggy_ohy...@ntlworld.ie>
Date: Fri, 22 Oct 2004 22:43:47 GMT
Local: Fri, Oct 22 2004 6:43 pm
Subject: Re: subnet calculations
this is what im trying to code a

simple Subnet Calculator for Class C IPv4 addresses.

The calculator should calculate subnet information for specified IPv4 Class
C network addresses only (ignore Class A and B). The user should input the
IP address for the Class C network, the number of network bits in the
address (since it could be a subnetted address already), and the number of
bits to borrow for subnetting.

e.g.

            192.168.10.0     - Class C IP network address

            24                     - number of network bits in address

            2                      - number of bits to borrow

dont no if this will help anyone..

but all help is welcome

"Morten Wennevik" <MortenWenne...@hotmail.com> wrote in message

news:opsf9y3qbeklbvpo@pbn_computer...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Morten Wennevik  
View profile  
 More options Oct 23 2004, 8:41 am
Newsgroups: microsoft.public.dotnet.languages.csharp
From: "Morten Wennevik" <MortenWenne...@hotmail.com>
Date: Sat, 23 Oct 2004 14:41:40 +0200
Local: Sat, Oct 23 2004 8:41 am
Subject: Re: subnet calculations
On Fri, 22 Oct 2004 22:43:47 GMT, Shaggyh <shaggy_ohy...@ntlworld.ie>  
wrote:

Well, if I understand you right, you get a 255.255.255.0 subnet (24 bits).
What do you mean by 2 bits to borrow?  2 bits out of the last 8-bit range?
In that case you will get
11111111.11111111.11111111.11000000 = 255.255.255.192

Consider the ip address as a 32 bit long number.  24+2 is 26 bits
If you put -1 in an integer you will get the number

11111111111111111111111111111111

Push this number left as many positions as you lack to get full 32 bits

int n = -1;
n <<= (32 - 26);

n is now

11111111111111111111111111000000

You can convert this number back to a subnet string by splitting it in  
chunks of 8 bytes
We can do that by using AND (&) with 11111111 (255)

   11111111111111111111111111000000
& 00000000000000000000000011111111
= 00000000000000000000000011000000 = 192

n & 255

Push the number right 8 bits and we get

n >>= 8;

   00000000111111111111111111111111 (->11000000)
& 00000000000000000000000011111111
= 00000000000000000000000011111111 = 255

In the end you will have something like

int n = -1;
n <<= (32 - networkbits - borrowedbits);
string subnet = (n & 255).ToString();
n >>= 8;
subnet = (n & 255) + "." + subnet;
n >>= 8;
subnet = (n & 255) + "." + subnet;
n >>= 8;
subnet = (n & 255) + "." + subnet;

subnet is now "255.255.255.192"

--
Happy Coding!
Morten Wennevik [C# MVP]


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google