我一直在为此头疼。
我想要的是制作一个小的 python 程序,它会输出一个带有相应 NIC 的 ipadress 列表
在PowerShell中,这样做是可能的,我在互联网上找到了这个脚本:
function Get-IscsiPortNumber {
$PortalSummary = @()
$portalInfo = get-wmiobject -namespace root\wmi -class msiscsi_portalinfoclass
$eScriptBlock ={([Net.IPAddress]$_.ipaddr.IPV4Address).IPAddressToString}
$customLabel = @{Label="IpAddress"; expression = $eScriptBlock}
foreach ($portal in $portalInfo) {
foreach ($p in ($portal.portalinformation)) {
$CurrentPort = New-Object PsObject -Property @{
Instance = ($portal.instancename).ToUpper()
Port = $p.port
IP = ([net.ipaddress]$p.ipaddr.IpV4Address).IPAddressToString
}
$PortalSummary += $CurrentPort
}
}
return $PortalSummary
}
Get-IscsiPortNumber | ft -AutoSize
不过,这不适用于所有 Windows 版本。例如,我在 Windows Server 2003 框中收到此错误消息:
PS C:\Documents and Settings\Administrator\Desktop> .\test.ps1
New-Object : A parameter cannot be found that matches parameter name 'Property'.
At C:\Documents and Settings\Administrator\Desktop\test.ps1:8 char:57
+ $CurrentPort = New-Object PsObject -Property <<<< @{
New-Object : A parameter cannot be found that matches parameter name 'Property'.
At C:\Documents and Settings\Administrator\Desktop\test.ps1:8 char:57
+ $CurrentPort = New-Object PsObject -Property <<<< @{
New-Object : A parameter cannot be found that matches parameter name 'Property'.
At C:\Documents and Settings\Administrator\Desktop\test.ps1:8 char:57
+ $CurrentPort = New-Object PsObject -Property <<<< @{
New-Object : A parameter cannot be found that matches parameter name 'Property'.
At C:\Documents and Settings\Administrator\Desktop\test.ps1:8 char:57
+ $CurrentPort = New-Object PsObject -Property <<<< @{
PS C:\Documents and Settings\Administrator\Desktop>
我对 ps 的经验几乎为零,所以我真的不知道为什么……在过去的几个小时里,我试图用 ps 和 wmi objectbrowser 探索 wmi。在 objectbrowser 中,我可以完美地看到我需要的所有统计信息。看截图。由于我实际上不知道数组和属性等如何在 ps 中工作,我希望有人可以帮助我。
问候