-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnet.sh
31 lines (29 loc) · 1.09 KB
/
net.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh
set -e
yush_resolv_v4() {
_server=
[ "$#" -ge "2" ] && _server=$2
_host=
_rx_ip='[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
if [ -z "$_host" ] && command -v dig 2>1 >/dev/null; then
if [ -n "$_server" ]; then
_host=$(dig +short @"$_server" "$1" | grep -Eo -e "$_rx_ip" | tail -n 1)
else
_host=$(dig +short "$1" | grep -Eo -e "$_rx_ip" | tail -n 1)
fi
fi
if [ -z "$_host" ] && command -v getent 2>1 >/dev/null; then
_host=$({ getent ahostsv4 "$1" 2>/dev/null || true; } | grep -Eo -e "$_rx_ip" | head -n 1)
fi
if [ -z "$_host" ] && command -v nslookup 2>1 >/dev/null; then
if [ -n "$_server" ]; then
_host=$({ nslookup "$1" "$_server" 2>/dev/null || true; } | grep -Eo -e "$_rx_ip" | head -n 1)
else
_host=$({ nslookup "$1" 2>/dev/null || true; } | grep -Eo -e "$_rx_ip" | head -n 1)
fi
fi
if [ -z "$_host" ] && command -v host 2>1 >/dev/null; then
_host=$(host "$1" | grep -Eo -e "$_rx_ip" | head -n 1)
fi
printf %s\\n "$_host"
}