纯用Excel写公式挺麻烦的
假设你的IP是在格子A1里
随便找两个格子分割IP和掩码长度,比如
A3是独立IP部分:"=LEFT(A1,FIND("/",A1)-1)"
A4是掩码长度:"=RIGHT(A1,LEN(A1)- FIND("/",A1))"
然后把掩码长度转换成掩码
A6生成二进制的掩码:"=TEXT(REPT("1",A4)&REPT("0",32-A4)"
A7生成十进制的掩码:"=BIN2DEC(LEFT(A6,8)) & "." & BIN2DEC(MID(A6,9,8)) & "." & BIN2DEC(MID(A6,17,8)) & "." & BIN2DEC(MID(A6,25,8))"
最后生成网关比较麻烦
先把分割IP成四个部分
A9:=LEFT(A3,FIND("~",SUBSTITUTE(A3,".","~",1))-1)
A10:=MID(A3,FIND("~",SUBSTITUTE(A3,".","~",1))+1,FIND("~",SUBSTITUTE(A3,".","~",2))-FIND("~",SUBSTITUTE(A3,".","~",1))-1)
A11:=MID(A3,FIND("~",SUBSTITUTE(A3,".","~",2))+1,FIND("~",SUBSTITUTE(A3,".","~",3))-FIND("~",SUBSTITUTE(A3,".","~",2))-1)
A12:=MID(A3,FIND("~",SUBSTITUTE(A3,".","~",3))+1,LEN(A3)-FIND("~",SUBSTITUTE(A3,".","~",3)))
和掩码二进制AND运算,假设放在B列
B9:=BITAND(BIN2DEC(LEFT(A6,8)),A9)
B10:=BITAND( BIN2DEC(MID(A6,9,8)),A10)
B11:=BITAND(BIN2DEC(MID(A6,17,8)),A11)
B12:=BITAND(BIN2DEC(MID(A6,25,8)),A12)+1
记得B12要+1,代表网关(第一个可用地址)
最后在A14整合网关地址:=B9 & "." & B10 & "." & B11 & "." & B12
|