Code to get the IP address and format it to run in nmap
You can do it purely in Bash, using ${parameter%word} to strip off the last octet from the IP address.

hostname -I | while read ip _ ; do
    nmap -sn  ${ip%.*}.\*
done


Note that hostname -I is not portable: the -I option appears to be a GNU extension.