File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21886,24 +21886,27 @@ filter_ip4_address() {
2188621886
2188721887# For security testing sometimes we have local entries. Getent is BS under Linux for localhost: No network, no resolution
2188821888# arg1 is the entry we want to look up in the host file
21889+ #
2188921890get_local_aaaa() {
2189021891 local ip6=""
2189121892 local etchosts="/etc/hosts /c/Windows/System32/drivers/etc/hosts"
2189221893
2189321894 [[ -z "$1" ]] && echo "" && return 1
21894- # Also multiple records should work fine
21895- ip6=$(grep -wih "$1 " $etchosts 2>/dev/null | grep ':' | grep -Ev '^#|\.local' | grep -Ei "[[:space:]]$1" | awk '{ print $1 }')
21895+ # grep: find hostname with trailing lf or space. -w doesn't work here
21896+ ip6=$(grep -Eih "[[:space:]]$1([[:space:]]|$) " $etchosts 2>/dev/null | grep ':' | grep -Ev '^#|\.local' | awk '{ print $1 }')
2189621897 if is_ipv6addr "$ip6"; then
2189721898 echo "$ip6"
2189821899 else
2189921900 echo ""
2190021901 fi
2190121902}
21903+
2190221904get_local_a() {
2190321905 local ip4=""
2190421906 local etchosts="/etc/hosts /c/Windows/System32/drivers/etc/hosts"
2190521907
21906- ip4=$(grep -wih "$1" $etchosts 2>/dev/null | grep -Ev ':|^#|\.local' | grep -Ei "[[:space:]]$1" | awk '{ print $1 }')
21908+ # grep: find hostname with trailing lf or space. -w doesn't work here
21909+ ip4=$(grep -Eih "[[:space:]]$1([[:space:]]|$)" $etchosts 2>/dev/null | grep -Ev ':|^#|\.local' | awk '{ print $1 }')
2190721910 if is_ipv4addr "$ip4"; then
2190821911 echo "$ip4"
2190921912 else
You can’t perform that action at this time.
0 commit comments