Bash command to convert IP addresses into their "reverse" form?
When I run nslookup on an IP (These are all examples)
nslookup 192.168.1.123
Current output:
411.311.211.111
Desired output:
111.211.311.411
I have a script that works just seeing if there's a more efficient way or a built-in nslookup command.
Thanks
echo 411.311.211.111 | awk -F. '{print $4"."$3"." $2"."$1}'
Output:
111.211.311.411
or
echo 411.311.211.111 | awk -F. '{OFS="."; print $4,$3,$2,$1}'
Here is a native function. Call it like reverseip 12.34.56.78
to have it print 78.56.34.12
. Call it like reversed=$(reverseip 12.34.56.78)
to capture the output into a variable.
reverseip () {
local IFS
IFS=.
set -- $1
echo $4.$3.$2.$1
}