views:

490

answers:

1

My goal is to calculate the directed broadcast address when given the IP and subnet mask of a host node. I know, sounds like homework. Once I reasoned through my task and boiled it down to this, I was amused with myself. Anyway, the solution will look something like the one in this question I suppose, but I'm not a math major and my C sucks. I could do with a PowerShell (preferred) or C# example to get me going.

thanks!

+4  A: 

See here for some PowerShell functions for IP math, including one that will calculate the broadcast address. The problem with using straight-up -bNot for the calculation is that it returns a signed int64, which kind of messes up any bitwise operations that are needing unsigned representation of the number.

James Kolpack
Yes, noticed that already. Deleting. Also, to halr9000: You shouldn't use the `Address` property; it's marked obsolete in the documentation.
Joey
Yes, the behavior of `-bNot` is kind of odd, considering that the bitwise not in C# evaluates to the same type as the operand.
James Kolpack
Thanks for the note about Address. That's the sort of thing that's not obvious from within the console. :)
halr9000
It is marked as obsolete. It isn't really hard to work with addresses if you spend some time looking at them in binary. My subnet calculator shows network, host, mask, directed broadcast, as string and binary. If you are interested it is here http://www.vbforums.com/showthread.php?p=3789524#post3789524
dbasnett