[aklug] Re: perl doesn't natively do booleans?????

From: Michael Fowler <michael@shoebox.net>
Date: Thu Aug 19 2010 - 09:30:44 AKDT

On Wed, Aug 18, 2010 at 05:43:02PM -0800, bryanm@acsalaska.net wrote:
> Okay, you've piqued my interest. I'm aware that an IP address can
> be expressed as a single integer (e.g. 127.0.0.1 = 2130706433).
> What other forms are there for a numerical address?

127.1 = 127.0.0.1 # class C
127.1.2 = 127.1.0.2 # class B
127.501 = 127.0.1.245 # more class C
127.1.318 = 127.1.1.62 # more class B
2130706433 = 127.0.0.1 # decimal integer
0x7f000001 = 127.0.0.1 # hex integer
017700000001 = 127.0.0.1 # octal integer
0x7f.0.0.0x1 = 127.0.0.1 # hex octets
0177.0.0.01 = 127.0.0.1 # octal octets
0xc0.0250.1.2 = 192.168.1.2 # mixed octets

Don't believe me? Observe this commercial!

perl -MSocket -wle 'print "$_ = ", inet_ntoa(inet_aton($_)) for @ARGV' 127.1 ...

Be warned, it will emit strange errors on unrecognized input addresses.
Something more robust would need to check inet_aton's return value
before passing it to inet_ntoa.

--
Michael Fowler
www.shoebox.net
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Thu Aug 19 10:04:54 2010

This archive was generated by hypermail 2.1.8 : Thu Aug 19 2010 - 10:04:54 AKDT