Solved

Get your network ID  by inputing your IP address and Mask

Posted on 2006-11-12
1
587 Views
Last Modified: 2010-04-15
 I need to write a code in C language where my IP address and my mask is used as input(from command prompt) and output is rang of IP addresses of network where I belong.

    Example:  

WHAT IS YOUR IP ADDRESS: 192.168.0.6

WHAT IS YOUR MASK: 255.255.255.0

YOU ARE PART OF NETWORK

192.168.0.1-192.168.0.254

192.168.0.0/24

 

Example 2:  

WHAT IS YOUR IP ADDRESS: 10.254.20.6

WHAT IS YOUR MASK: 255.255.254.0

YOU ARE PART OF NETWORK

10.254.20.1-10.254.21.254

10.254.20.0/23
0
Comment
Question by:itscrew
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 17926269
See e.g. http://steve-parker.org/code/c/netmask.c

This code outputs that as

C:\tmp\cc>netmask 192.168.0.6/255.255.255.0
IP        = 192.168.000.006
Mask      = 255.255.255.000 (ffffff00) - aka /24
Network   = 192.168.000.000
Broadcast = 192.168.000.255

and

C:\tmp\cc>netmask 10.254.20.6/255.255.254.0
IP        = 010.254.020.006
Mask      = 255.255.254.000 (fffffe00) - aka /23
Network   = 010.254.020.000
Broadcast = 010.254.021.255

respectively.


0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now