nmip.sh: find LAN IP with ip instead of ifconfig

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 14:59:00 -04:00
co-authored by Claude Opus 5.5
parent 5d6f07e51d
commit 4c10b9e110
+3 -3
View File
@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
lanip=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p') lanip=$(ip -4 route get 1.1.1.1 2>/dev/null | awk '{for (i = 1; i < NF; i++) if ($i == "src") {print $(i + 1); exit}}')
# Colors # Colors
RED='\033[0;31m' RED='\033[0;31m'
@@ -20,9 +20,9 @@ NC='\033[0m' # No Color
if [ ! -f /usr/bin/nmap ];then if [ ! -f /usr/bin/nmap ];then
printf "${LRED} Nmap is not installed...${NC}\n" printf "${LRED} Nmap is not installed...${NC}\n"
elif [ ! -z "${1}" ];then elif [ ! -z "${1}" ];then
nmap -sP "${1}/24" nmap -sn "${1}/24"
else else
printf "${LGREEN}Looking up ${lanip}...${NC}\n" printf "${LGREEN}Looking up ${lanip}...${NC}\n"
nmap -sP ${lanip}/24 # Use sudo to get names of devies nmap -sn ${lanip}/24 # Use sudo to get names of devies
fi fi