Code to get the IP address and format it to run in nmap

For scanning my subnet using my IP address, I need to run the following command

nmap -sn 192.168.100.* 

I want to extend this functionality such that I don’t have to manually specify the first three parts of the IP range myself. I came up with this rough solution.

ip=$  ( hostname -I | awk '{print $  1}' | awk -F. '{print $  1; print $  2; print $  3}' ORS="."; echo -n "*");  nmap -sn $  ip 

Is there a more cleaner way of achieving the same?