例如:
如何获得CIDR表示法10.66.114.0/24的更高IP地址
在这种情况下,答案是:
10.66.114.1 - 10.66.114.254
答案 0 :(得分:4)
这是它的要点(我是C家伙):
unsigned int network = 0x0a427200; /* 10.66.114.0 */
unsigned int subnet_length = 24;
unsigned int mask = 0xfffffff << (32 - subnet_length);
unsigned int bcast = 0xffffffff >> (32 - subnet_length);
unsigned int start_ip = (network & mask) + 1;
unsigned int end_ip = (network & mask) + (bcast - 1);
答案 1 :(得分:-1)
#include <ncurses.h>
// ncurses.h includes stdio.h
#include <math.h>
#include <stdlib.h>
// determine network range of masked ip. eg: 192.168.113.0/25
// unsigned int network = 0x0a427200; /* 10.66.114.0 */
// unsigned int subnet_length = 24;
//
// unsigned int mask = 0xfffffff << (32 - subnet_length);
// unsigned int bcast = 0xffffffff >> (32 - subnet_length);
//
// unsigned int start_ip = (network & mask) + 1;
// unsigned int end_ip = (network & mask) + (bcast - 1);
int main(int argc, char *argv[])
{
// char arg[50] = " ";
char ipmask[50] = "192.168.113.0/25";
// determine network range of masked ip. eg: 192.168.113.0/25
unsigned int network = 0xc0a87100; /* 192.168.113.0 */
unsigned int subnet_length = 25;
unsigned int mask = 0xfffffff << (32 - subnet_length);
unsigned int bcast = 0xffffffff >> (subnet_length);
// unsigned int bcast = 0xffffffff >> (32 - subnet_length);
unsigned int start_ip = (network & mask) + 1;
unsigned int end_ip = (network & mask) + (bcast);
initscr();
cbreak();
printw("\nipmask %s\nstart %x end %x range %x\n"
"press any key\n", ipmask, start_ip, end_ip, end_ip - start_ip + 1);
getch();
endwin(); // close ncurses library and restores previous console
return(0);
}
/*****************************************************************************/
// end netmask
gcc -Wall netmask.c -o netmask -lm -lncurses