2019-12-06 16:31:10 -05:00
|
|
|
#!/bin/bash
|
2017-06-05 23:24:55 -04:00
|
|
|
# convert integer to IP
|
|
|
|
int2ip () {
|
2019-12-06 16:31:10 -05:00
|
|
|
local ip dec=("$@")
|
2017-06-05 23:24:55 -04:00
|
|
|
for e in {3..0}
|
|
|
|
do
|
|
|
|
((octet = dec / (256 ** e) ))
|
|
|
|
((dec -= octet * 256 ** e))
|
|
|
|
ip+=$delim$octet
|
|
|
|
delim=.
|
|
|
|
done
|
|
|
|
printf '%s\n' "$ip"
|
|
|
|
unset delim
|
|
|
|
}
|
|
|
|
|
|
|
|
# convert IP to integer
|
|
|
|
ip2int () {
|
2019-12-06 16:31:10 -05:00
|
|
|
local a b c d ip
|
|
|
|
ip=("$@")
|
|
|
|
IFS=. read -r a b c d <<< "${ip[*]}"
|
2017-06-05 23:24:55 -04:00
|
|
|
printf '%d\n' "$((a * 256 ** 3 + b * 256 ** 2 + c * 256 + d))"
|
|
|
|
}
|