ip2bin('255.255.255.0', ' ') returns 11111111 11111111 11111111 00000000
Update:
Another way to do this is to use the inet_aton function in the Socket module. A perl one liner to produce the same output:
perl -MSocket -e 'printf ("%s %s %s %s", unpack('B8B8B8B8', inet_aton('255.255.255.0')))'
Thanks AgentM for the pointer.
sub ip2bin{ my ($ip, $delimiter) = @_; return join($delimiter, map substr(unpack("B32",pack("N",$_)),-8), split(/\./,$ip)); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Converting decimal IP addresses to binary
by AgentM (Curate) on Jan 30, 2001 at 23:49 UTC | |
by Coyote (Deacon) on Jan 31, 2001 at 00:35 UTC | |
by AgentM (Curate) on Jan 31, 2001 at 00:39 UTC | |
by Coyote (Deacon) on Jan 31, 2001 at 01:35 UTC |