When I run nslookup on an IP (These are all examples)
nslookup 192.168.1.123
Current output:
41.31.211.111
Desired output:
111.211.31.41
I have a script that works just seeing if there's a more efficient way or a built-in nslookup
command.
Output:
or
Here is a native function. Call it like
reverseip 12.34.56.78
to have it print78.56.34.12
. Call it likereversed=$(reverseip 12.34.56.78)
to capture the output into a variable.set
with a string argument tokenizes this string into$1
,$2
, etc based on the current value ofIFS
. So we are breaking up the function's input argument$1
into tokens, which now replace the original$1
,$2
, etc. BecauseIFS
is a dot, the input value in the original$1
gets split up on dots. The dash--
is a safety measure to signal the end of options toset
, in case the actual value of$1
would start with a dash (without the--
you would then get an "unknown option" error, or, worse, random or even insecure behavior).