Hello,
I'm trying to write a script in shell that prints me a list of the IP addresses with masks in format aaa.bbb.ccc.ddd/AA but, no way to get the mask in decimal notation.
here is the result :
The script is the following:
I've did some search on the internet and found theses 2 expression in perl, but did not find the way to use theme ( integrate into the script )
So, ... help needed please.
Thank you in advence.
I'm trying to write a script in shell that prints me a list of the IP addresses with masks in format aaa.bbb.ccc.ddd/AA but, no way to get the mask in decimal notation.
here is the result :
root@uc1-bejaia [ /uccenos/bin ] # sh uc.notwan
127.0.0.1 0xff000000
192.168.100.254 0xffffff00
The script is the following:
sh:
#!/bin/sh
############################################################################
# not ready .
# trying to get ip/mask but not succed 192.168.2.22/24
############################################################################
# Return default interface address to the internet
_if_wan=$(route -n get default | grep 'if address:' | grep -o '[^ ]*$')
# Return all address on the system but not Wan
_if_unbound=$(ifconfig -a inet| grep inet | grep -v "$_if_wan" | awk '{ print $2, $4 }')
echo "$_if_unbound"
I've did some search on the internet and found theses 2 expression in perl, but did not find the way to use theme ( integrate into the script )
sh:
echo "ffffff00" | perl -pe '$_ = join(".", map(hex, /.{2}/g))'
=> 255.255.255.0
echo "ffffff00" | perl -pe '$_ = unpack("B32", pack("H*", $_)); s/0+$//g; $_ = length'
=> 24
So, ... help needed please.
Thank you in advence.