Skip to content

Commit

Permalink
MSF-368 - Simplifying get IP scrip.
Browse files Browse the repository at this point in the history
  • Loading branch information
milos85vasic committed Dec 10, 2020
1 parent 2cc0d17 commit 0556c76
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions getip.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
#!/bin/sh

address=$1
error="Could not obtain ip address for: $address"
if ! which nslookup >/dev/null 2>&1 ||
nslookup "$address" | grep "can't find" >/dev/null 2>&1; then

ping -c1 "$address" | sed -nE 's/^PING[^(]+\(([^)]+)\).*/\1/p'
else

addr="Address:"
lookup_data=$(nslookup "$address" | sed '/^[[:space:]]*$/d' | grep "$addr")
addresses=$(echo "$lookup_data" | tr -d "[:blank:]")
addresses=$(echo "$addresses" | sed -e "s/^$addr//" | tr '\r\n' ';')
export IFS=";"
for candidate in $addresses; do

if expr "$candidate" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null 2>&1; then

echo "$candidate"
exit 0
fi
done

echo "$error"
exit 1
fi
ping -c1 "$1" | sed -nE 's/^PING[^(]+\(([^)]+)\).*/\1/p'

0 comments on commit 0556c76

Please sign in to comment.