- 论坛徽章:
- 0
|
来个简单的,只支持c类地址(掩码大于等于24)- awk -v OFS="." -F"[./]" '{m=$5;chk=32-m;
- if(chk<8){
- hostnum=2^chk-2;
- netnum=2^(8-chk);
- stepnum=2^(chk);
- for(i=0;i<255;i=i+stepnum){
- if ($4>=i && $4<=i+stepnum){
- mask=i;
- }
- }
- print "netmask: "$1,$2,$3,mask;
- print "broadcast: "$1,$2,$3,mask+stepnum;
- print "Available IP:"
- for(i=mask+1;i<mask+stepnum;i++){
- print $1,$2,$3,i;
- }
- }
- if (chk==8){
- for(i=1;i<255;i++){
- print $1,$2,$3,i;
- }
- }
- }' file
复制代码 结果:- file:
- 192.168.1.72/28
- IP:
- 192.168.1.65
- 192.168.1.66
- 192.168.1.67
- 192.168.1.68
- 192.168.1.69
- 192.168.1.70
- 192.168.1.71
- 192.168.1.72
- 192.168.1.73
- 192.168.1.74
- 192.168.1.75
- 192.168.1.76
- 192.168.1.77
- 192.168.1.78
- 192.168.1.79
复制代码 |
|