9

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

10
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}'
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
}
0

Using sed:

sed -r 's/([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})/\4.\3.\2.\1/'

Match IP address and print from last to first(reverse)

  • A bit unwieldy to look at but works none-the-less, thanks! – Roboman1723 Dec 10 '14 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.