开发者

shell script + calculate NETWORK IP by shell script

the following question relev开发者_运维百科ant for ksh script

how to calculate the NETWORK IP according to NETMASK & IP ADDRES

if there are some ready shell script to calculate the NETWORK IP

for example

  NETMASK=255.255.255.0
  IP=172.18.20.10


  then NETWORK IP should be 172.18.20.0

lidia


Give this a try:

#!/bin/ksh
saveIFS=$IFS
IFS="."
ip=($1)
mask=($2)
for i in {0..3}
do
    (( result[i] = ip[i] & mask[i] ))
done
echo "${result[*]}"
IFS=$saveIFS

Example:

$ ./netip.ksh 172.18.20.10 255.255.255.0
172.18.20.0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜