5 c=and(rshift(c, 1),0x55555555)+and(c,0x55555555)
6 c=and(rshift(c, 2),0x33333333)+and(c,0x33333333)
7 c=and(rshift(c, 4),0x0f0f0f0f)+and(c,0x0f0f0f0f)
8 c=and(rshift(c, 8),0x00ff00ff)+and(c,0x00ff00ff)
9 c=and(rshift(c,16),0x0000ffff)+and(c,0x0000ffff)
14 for (ret=0,n=split(ip,a,"\."),x=1;x<=n;x++) ret=or(lshift(ret,8),a[x])
18 function int2ip(ip,ret,x) {
21 for(;x<3;ret=and(ip,255)"."ret,ip=rshift(ip,8),x++);
26 slpos=index(ARGV[1],"/")
28 ipaddr=ip2int(ARGV[1])
29 netmask=ip2int(ARGV[2])
31 ipaddr=ip2int(substr(ARGV[1],0,slpos-1))
32 netmask=compl(2**(32-int(substr(ARGV[1],slpos+1)))-1)
37 network=and(ipaddr,netmask)
38 broadcast=or(network,compl(netmask))
40 start=or(network,and(ip2int(ARGV[3]),compl(netmask)))
42 if (start<limit) start=limit
45 limit=or(network,compl(netmask))-1
46 if (end>limit) end=limit
48 print "IP="int2ip(ipaddr)
49 print "NETMASK="int2ip(netmask)
50 print "BROADCAST="int2ip(broadcast)
51 print "NETWORK="int2ip(network)
52 print "PREFIX="32-bitcount(compl(netmask))
55 # ipcalc <ip> <netmask> <start> <num>
58 print "START="int2ip(start)
59 print "END="int2ip(end)
This page took 0.052792 seconds and 5 git commands to generate.