Given the IP and netmask, how can I calculate the network address using bash?

后端 未结 6 950
耶瑟儿~
耶瑟儿~ 2020-12-24 03:20

In a bash script I have an IP address like 192.168.1.15 and a netmask like 255.255.0.0. I now want to calculate the start address of this network, that means using the &

6条回答
  •  误落风尘
    2020-12-24 03:48

    Great answer, though minor typo in answer above.

    $ printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$(($i2  <-- $i2 should be i2
    

    If anyone knows how to calculate the broadcast address (XOR the network), then calculate the usable nodes between network and broadcast I'd be interested in those next steps. I have to find addresses in a list within a /23.

提交回复
热议问题