且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

返回给定IP地址和子网掩码的IP地址列表的函数

更新时间:2023-10-30 18:52:34

1)首先你可以转换 ipaddress 子网掩码从字符串格式到二进制格式,带 inet_pton()

1) first you can transform the ipaddress and the subnetmask from string format to binary format with inet_pton().

2)制作一个检查子网掩码掩码它应该是有效的子网掩码

2) make a check on the subnetmask mask it should be a valid subnet mask

3)获取 subnetmask 反向值( ~pubnetmask

4)

for (i=1; i<(~subnetmask); i++) {

    ip = ipaddress & (subnetmask + i);

    //append ip to your ip list

}