Public feed #604462

Someone

public shellscript v1 · immutable
Raw Edit
·published 2007-07-05 15:18 UTC
rendered paste body
#!/bin/bashIpAndNetmasktoNetwork(){  # expects $1 to be an ip address  # expects $2 to be a netmask  IP1="${1%.*.*.*}"  IP2="${1%.*.*}"  IP2="${IP2#*.}"  IP3="${1%.*}"  IP3="${IP3#*.*.}"  IP4="${1#*.*.*.}"  NM1="${2%.*.*.*}"  NM2="${2%.*.*}"  NM2="${NM2#*.}"  NM3="${2%.*}"  NM3="${NM3#*.*.}"  NM4="${2#*.*.*.}"  let "ipdec=$IP4 + (256*$IP3) + (256*256*$IP2) + (256*256*256*$IP1)"  let "nmdec=$NM4 + (256*$NM3) + (256*256*$NM2) + (256*256*256*$NM1)"  let "ipnet=$ipdec%$nmdec"  count=0  let "nmtemp=$nmdec"  while [ $nmtemp -eq $nmdec ]  do    let "count+=1"    let "nmtemp >>= $count+1"    let "nmtemp <<= $count+1"  done  ipnet=$ipdec  let "ipnet >>= $count"  let "ipnet <<= $count"  let "bits=32-$count"  let "IPNET1=$ipnet/256/256/256"  let "IPNET2=($ipnet-($IPNET1*256*256*256))/256/256"  let "IPNET3=($ipnet-($IPNET1*256*256*256)-($IPNET2*256*256))/256"  let "IPNET4=($ipnet-($IPNET1*256*256*256)-($IPNET2*256*256)-($IPNET3*256))"  ipnet="$IPNET1.$IPNET2.$IPNET3.$IPNET4/$bits"  echo $ipnet}INTIP="192.168.10.100"INTMASK="255.255.255.0"intnm="`IpAndNetmasktoNetwork "$INTIP" "$INTMASK"`"echo $intnm