rename default/ to files/
[openwrt.git] / package / base-files / files / bin / ipcalc
1 #!/bin/sh
2
3 awk -f /usr/lib/common.awk -f - $* <<EOF
4 BEGIN {
5 ipaddr=ip2int(ARGV[1])
6 netmask=ip2int(ARGV[2])
7 network=and(ipaddr,netmask)
8 broadcast=or(network,compl(netmask))
9
10 start=or(network,and(ip2int(ARGV[3]),compl(netmask)))
11 limit=network+1
12 if (start<limit) start=limit
13
14 end=start+ARGV[4]
15 limit=or(network,compl(netmask))-1
16 if (end>limit) end=limit
17
18 print "IP="int2ip(ipaddr)
19 print "NETMASK="int2ip(netmask)
20 print "BROADCAST="int2ip(broadcast)
21 print "NETWORK="int2ip(network)
22 print "PREFIX="32-bitcount(compl(netmask))
23
24 # range calculations:
25 # ipcalc <ip> <netmask> <start> <num>
26
27 if (ARGC > 3) {
28 print "START="int2ip(start)
29 print "END="int2ip(end-1)
30 }
31 }
32 EOF
This page took 0.042784 seconds and 5 git commands to generate.