Solved

Get your network ID  by inputing your IP address and Mask

Posted on 2006-11-12
1
594 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
voltage to force translation ? 8 100
Best UNIX-compatible free C compiler for Windows or Mac 6 267
Read file descriptor 3 in C 14 121
Why does module make constant click noise ? 9 141
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

735 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