You can also use Net::Netmask:

use Net::Netmask;

my $block = Net::Netmask->new2('192.168.1.33', '255.255.255.192') or die;
print $block->broadcast, "\n";

Hope this helps!

--John

On 6/5/05, Bob Rogers <[EMAIL PROTECTED]> wrote:
>   From: J Finn <[EMAIL PROTECTED]>
>   Date: Sun, 5 Jun 2005 20:26:42 -0400
> 
>   I've got a quick question I'm hoping someone can answer.
> 
>   If I've got a server with 3 interfaces on three different network, Is
>   there a portable way in perl to get the broadcast addresses of each
>   of those networks?
> 
>   for example, if I've got an ip address: 192.168.1.33 and the netmask
>   is 255.255.255.192 (range .32-.63), how can I find the broadcast
>   address (192.168.1.63)?
> 
>   Thanks
> 
>   -jf
> 
> Depends on what you mean by 'portable.'  I just pull the answer directly
> from the output of ifconfig.  That is probably safest, as this may have
> something different from the value you would compute:
> 
>    eth1      Link encap:Ethernet  HWaddr 00:90:27:BD:F2:6F
>              inet addr:24.34.108.24  Bcast:255.255.255.255  Mask:255.255.248.0
>              inet6 addr: fe80::290:27ff:febd:f26f/64 Scope:Link
>              UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1
>              RX packets:30307825 errors:0 dropped:0 overruns:0 frame:0
>              TX packets:3937613 errors:0 dropped:0 overruns:0 carrier:0
>              collisions:0 txqueuelen:100
>              RX bytes:2770021884 (2641.6 Mb)  TX bytes:1617715374 (1542.7 Mb)
>              Interrupt:11 Base address:0xd000 Memory:eb100000-eb100038
> 
> The 'Bcast:' value in this case was supplied by the Comcast DHCP server;
> I just now noticed this for the first time.  I wouldn't be surprised to
> learn that it violates all kinds of RFCs, though.  It could be that
> doing it that way makes it easier for them to block broadcasts from
> noisy Windows clients, but that's just a guess.
> 
>                                        -- Bob Rogers
>                                           http://rgrjr.dyndns.org/
> 
> _______________________________________________
> Boston-pm mailing list
> [email protected]
> http://mail.pm.org/mailman/listinfo/boston-pm
> 


-- 
John West                    [EMAIL PROTECTED]
-><- 'tis an ill wind that blows no minds -><-
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to