C语言IP地址解析器编写方法
1、打开VC++6.0
2、点击,文件,新建
3、填写工程名字,选择C++ source file
4、这样就创建了一个空白工作区
5、首先,我们要写酋篚靶高需要的头文件#include <stdio.h>#include <stdlib.h>
6、之后,按格式写主函数
7、之后,我们必须声明要用到的变量unsigned long input_IP;unsigned int BeginByte,MidByte,ThirdByte,En颊俄岿髭dByte;unsigned int_rotate=0x07;
8、下面是主要代码print酆璁冻嘌f("请输入你需要解析的IP地址:");scanf("%lx",&input_朐袁噙岿IP);BeginByte = (input_IP >> 24) & ~(~0 << 8);//获取IP地址最高位MidByte = (input_IP >> 16) & ~(~0 << 8);//获取第二段ThirdByte = (input_IP >> 8 ) & ~(~0 << 8);//获取第三段EndByte = input_IP & ~(~0 << 8);//获取第四段printf("The IP address after parsed is: %d.%d.%d.%d\n",BeginByte,MidByte,ThirdByte,EndByte);/*两个循环移位函数*/ printf("%u after rotated twice is =%u\n",int_rotate,_rotl(int_rotate,2));printf("%u after rotated once is =%u\n",int_rotate,_rotr(int_rotate,1)); _rotl _rotr利用左移和右移函数,输出,可以确保信息不丢失
9、完成后点击编译和执行
10、程序运行
11、输入IP地址,后回车