远程轮询网络上的多个桌面/服务器以确定 IP 类型:静态或 DHCP
有一位先生回答了我最初问题的 90%,也就是说我现在能够轮询正在运行以下脚本的设备。最终目标是在我支持的网络上的所有桌面/服务器上获取 IP 类型:静态或 DHCP。我有一份将在批处理文件中输入的服务器列表,只是寻找代码来实际从一个位置轮询网络上的其他设备。
要查看的输出:
Device name: IP Address: MAC Address: Type: Marvell Yukon 88E8001/8003/8010 PCI Gigabit Ethernet Controller NULL 00:00:F3:44:C6:00 DHCP Generic Marvell Yukon 88E8056 based Ethernet Controller 192.168.1.102 00:00:F3:44:D0:00 DHCP
ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
txtLaunch.Text = ("Name\tIP Address\tMAC Address\tType" +"\r\n");
foreach (ManagementObject objMO in objMOC)
{
StringBuilder builder = new StringBuilder();
object o = objMO.GetPropertyValue("IPAddress");
object m = objMO.GetPropertyValue("MACAddress");
if (o != null || m != null)
{
builder.Append(objMO["Description"].ToString());
builder.Append("\t");
if (o != null)
builder.Append(((string[])(objMO["IPAddress"]))[0].ToString());
else
builder.Append("NULL");
builder.Append("\t");
builder.Append(m.ToString());
builder.Append("\t");
builder.Append(Convert.ToBoolean(objMO["DHCPEnabled"]) ? "DHCP" : "Static");
builder.Append("\r\n");
}
txtLaunch.Text = txtLaunch.Text + (builder.ToString());
我愿意接受这里的建议。
Had a gentleman answer 90% of my original question, which is to say I now have the ability to poll a device that I am running the below script on. The end goal is to obtain IP type: Static or DHCP on all desktop/servers on a network I support. I have the list of servers that I will input in a batch file, just looking for the code to actually poll the other devices on the network from one location.
Output to be viewed:
Device name: IP Address: MAC Address: Type: Marvell Yukon 88E8001/8003/8010 PCI Gigabit Ethernet Controller NULL 00:00:F3:44:C6:00 DHCP Generic Marvell Yukon 88E8056 based Ethernet Controller 192.168.1.102 00:00:F3:44:D0:00 DHCP
ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
txtLaunch.Text = ("Name\tIP Address\tMAC Address\tType" +"\r\n");
foreach (ManagementObject objMO in objMOC)
{
StringBuilder builder = new StringBuilder();
object o = objMO.GetPropertyValue("IPAddress");
object m = objMO.GetPropertyValue("MACAddress");
if (o != null || m != null)
{
builder.Append(objMO["Description"].ToString());
builder.Append("\t");
if (o != null)
builder.Append(((string[])(objMO["IPAddress"]))[0].ToString());
else
builder.Append("NULL");
builder.Append("\t");
builder.Append(m.ToString());
builder.Append("\t");
builder.Append(Convert.ToBoolean(objMO["DHCPEnabled"]) ? "DHCP" : "Static");
builder.Append("\r\n");
}
txtLaunch.Text = txtLaunch.Text + (builder.ToString());
I'm open to recommendations here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需要在远程计算机上实例化您的管理类。
此链接:远程 WMI 将为您提供您需要的代码。只需循环浏览每台机器即可获取您需要的信息。
您将需要对尝试连接的每台计算机具有管理员权限。您也许可以缩小规模,但这将有助于排除故障。
研究一下 PowerShell,它使用 WinRM 使这件事变得更加容易。
You just need to instantiate your management class on the remote machine.
This link: Remote WMI will give you the code you need. Just loop through with each machine and get the info you need.
You will need admin privileges on each machine that you are trying to connect to. You may be able to scale that back, but it will help with troubleshooting.
Look into PowerShell as well as it makes this stuff much easier with WinRM.
如果有些机器是 64 位的,而系统也是 64 位的,我们该怎么办?因为它搜索 32 位系统,不是吗?
它说:“从 Win32_OperatingSystem 选择*”
What will we do if some machines are 64bit and also systems are . Becouse it searches 32 bit systems ,isn't?
It says : "SELECT * FROM Win32_OperatingSystem"