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:
@@ -1,6 +1,6 @@
|
||||
#!/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
|
||||
RED='\033[0;31m'
|
||||
@@ -20,9 +20,9 @@ NC='\033[0m' # No Color
|
||||
if [ ! -f /usr/bin/nmap ];then
|
||||
printf "${LRED} Nmap is not installed...${NC}\n"
|
||||
elif [ ! -z "${1}" ];then
|
||||
nmap -sP "${1}/24"
|
||||
nmap -sn "${1}/24"
|
||||
|
||||
else
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user