Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Scripts to create an IP info summary display' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Scripts to create an IP info summary display
Authored by: eagle on Sep 02, '06 05:38:46AM

Doing that outputs the netmask in reverse order. Also, the public IP address area prints the complete HTML returned instead of just the IP address. If I knew enough about sed and unpack/pack, I'd fix it myself...

--------------------------------------------------------------------------------
Public: <html><head><title>Current IP Check</title></head><body>Current IP Address: 24.225.90.70</body></html>
Loopback: 127.0.0.1 / 0.0.0.255
Airport: 10.1.1.2 / 224.255.255.255
Gateway: 10.1.1.1
Domain: earthlink.net
Nameserver: 10.1.1.1
--------------------------------------------------------------------------------



[ Reply to This | # ]
Scripts to create an IP info summary display
Authored by: knouse on Sep 02, '06 12:50:13PM
the public IP address area prints the complete HTML returned instead of just the IP address

The sed command needs the -E option

get_public ()
{
        curl -s http://checkip.dyndns.org | sed -E 's/.*: ([^<]*)<.*/\1/'
}


[ Reply to This | # ]
Scripts to create an IP info summary display
Authored by: knouse on Sep 02, '06 01:40:41PM

And the replacement string must be escaped \1 instead of 1



[ Reply to This | # ]
Scripts to create an IP info summary display
Authored by: ScottTFrazer on Sep 06, '06 06:09:33AM

I get an error when I try to use -E with sed, changing it to -e doesn't really seem to work either.

Also, I always seem to reply to wrong thread. but that's a user issue :-)



[ Reply to This | # ]
Scripts to create an IP info summary display
Authored by: knouse on Sep 02, '06 02:32:06PM
Doing that outputs the netmask in reverse order

Since I don't know Perl I piped the output to sed to reverse the order

get_mask ()
{
        [ "$1" == "" ] && return
        ifconfig $1 | perl -nase 'print join(".",unpack("CCCC",pack("L*",oct $F[3]))) if (m/mask/);' \
            | sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/\4.\3.\2.\1/'
}



[ Reply to This | # ]