在 PowerShell 中计算给定 IP 地址和子网的定向广播地址
我的目标是在给定主机节点的 IP 和子网掩码的情况下计算定向广播地址。我知道,听起来像是家庭作业。一旦我推理出我的任务并将其归结为这一点,我就被自己逗乐了。无论如何,解决方案看起来类似于这个问题 我想,但我不是数学专业的,而且我的 C 很糟糕。我可以使用 PowerShell(首选)或 C# 示例来帮助我继续。
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅此处了解一些 PowerShell IP 数学函数,包括计算广播地址的函数。使用直接
-bNot
进行计算的问题是它返回一个有符号 int64,这会弄乱任何需要无符号数字表示的按位运算。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.这是我的,它使用 NetTCPIP< 中的
Get-NetIPAddress
/a> 和IPAddress
来自 系统.Net:Here is mine which uses
Get-NetIPAddress
from NetTCPIP andIPAddress
from the System.Net: