File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -22206,24 +22206,27 @@ filter_ip4_address() {
2220622206
2220722207# For security testing sometimes we have local entries. Getent is BS under Linux for localhost: No network, no resolution
2220822208# arg1 is the entry we want to look up in the host file
22209+ #
2220922210get_local_aaaa() {
2221022211 local ip6=""
2221122212 local etchosts="/etc/hosts /c/Windows/System32/drivers/etc/hosts"
2221222213
2221322214 [[ -z "$1" ]] && echo "" && return 1
22214- # Also multiple records should work fine
22215- ip6=$(grep -wih "$1 " $etchosts 2>/dev/null | grep ':' | grep -Ev '^#|\.local' | grep -Ei "[[:space:]]$1" | awk '{ print $1 }')
22215+ # grep: find hostname with trailing lf or space. -w doesn't work here
22216+ ip6=$(grep -Eih "[[:space:]]$1([[:space:]]|$) " $etchosts 2>/dev/null | grep ':' | grep -Ev '^#|\.local' | awk '{ print $1 }')
2221622217 if is_ipv6addr "$ip6"; then
2221722218 echo "$ip6"
2221822219 else
2221922220 echo ""
2222022221 fi
2222122222}
22223+
2222222224get_local_a() {
2222322225 local ip4=""
2222422226 local etchosts="/etc/hosts /c/Windows/System32/drivers/etc/hosts"
2222522227
22226- ip4=$(grep -wih "$1" $etchosts 2>/dev/null | grep -Ev ':|^#|\.local' | grep -Ei "[[:space:]]$1" | awk '{ print $1 }')
22228+ # grep: find hostname with trailing lf or space. -w doesn't work here
22229+ ip4=$(grep -Eih "[[:space:]]$1([[:space:]]|$)" $etchosts 2>/dev/null | grep -Ev ':|^#|\.local' | awk '{ print $1 }')
2222722230 if is_ipv4addr "$ip4"; then
2222822231 echo "$ip4"
2222922232 else
You can’t perform that action at this time.
0 commit comments