Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7722453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:10:43+00:00 2026-06-01T04:10:43+00:00

As I have to setup quite a few Windows Server machines, I decided to

  • 0

As I have to setup quite a few Windows Server machines, I decided to write a little program in C# to help simplify some of these tasks. The last one I have to add is the ability to input an IP Range (74.117.238.112/28 for example) and have it automatically add all of these as static IP’s to the NIC.

I have always used web calculators in the past for this, however I am trying to figure out how to do it programmatically in C#. I have found this write-up HERE, which makes a lot of sense (learned a bit from it) but is a bit confusing. The calculators I have used in the past presented me with Subnet masks like 255.255.255.240, or .248, where as this only seems to return one of four values.

Is this code example correct, or will it need to be modified further to actually be usable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:10:44+00:00Added an answer on June 1, 2026 at 4:10 am

    the link you mentioned gives you standard subnet masks for different IP classes. This is not really subnetting.

    If I understand you correctly, you only need the subnet mask, which is only dependent on the subnet (/28 in your example) and not the ip address.

    I wrote this small function::

        public static string GetSubnetMask(byte subnet)
        {
            long mask = (0xffffffffL << (32-subnet)) & 0xffffffffL;
            mask=IPAddress.HostToNetworkOrder((int)mask);
            return new IPAddress((UInt32)mask).ToString();
        }
    

    If you call it with a subnet (e.g. 28) it will return the subnet as a string (255.255.255.240).

    Tell me if this is what you needed or if there is anything else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have setup web dav on windows server 2008. It seems to work fine
I have wamp setup with quite a few websites setup as virtual hosts like
I'm quite new to git. I have a repo setup on a server (A)
I'm quite used to my IDE setup in Delphi 7, where I have my
I have setup a git repository in a linux server, and installed the latest
I have seen quite a few solutions on this kind of problem (esp. this
I know there are quite a few questions concerning access violations, but I have
I have quite a few working examples of jqGrid, and yesterday I added a
I know there have been quite a few posts on this but none seem
I have quite a few domains that I manage (100+) and I'm getting tired

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.