首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >显示NIC信息

显示NIC信息
EN

Stack Overflow用户
提问于 2013-07-15 06:14:17
回答 1查看 962关注 0票数 1

在下面的代码中,$ipAddress同时存储IPV4和IPV6。我只想要显示IPV4,有没有办法做到这一点?也许可以用分叉?

此外,子网掩码还会打印255.255.255.0 64 -这个恶意64是从哪里来的?

代码:

代码语言:javascript
复制
ForEach($NIC in $env:computername) {
    $intIndex = 1
    $NICInfo = Get-WmiObject -ComputerName $env:computername Win32_NetworkAdapterConfiguration | Where-Object {$_.IPAddress -ne $null}
    $caption = $NICInfo.Description 
    $ipAddress = $NICInfo.IPAddress
    $ipSubnet = $NICInfo.IpSubnet 
    $ipGateWay = $NICInfo.DefaultIPGateway 
    $macAddress = $NICInfo.MACAddress 
    Write-Host "Interface Name: $caption"
    Write-Host "IP Addresses: $ipAddress" 
    Write-Host "Subnet Mask: $ipSubnet"
    Write-Host "Default Gateway: $ipGateway"
    Write-Host "MAC: $macAddress"
    $intIndex += 1
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-15 09:40:39

对于IPv6,子网的工作方式不同,所以您看到的流氓64是IPV6的子网掩码,而不是IPV4的子网掩码。

IPv6中的前缀长度相当于IPv4中的子网掩码。但是,它不像在IPv4中那样以4个二进制八位数表示,而是表示为1-128之间的整数。例如: 2001:db8:abcd:0012::0/64

查看此处:http://publib.boulder.ibm.com/infocenter/ts3500tl/v1r0/index.jsp?topic=%2Fcom.ibm.storage.ts3500.doc%2Fopg_3584_IPv4_IPv6_prefix_subnet_mask.html

为了删除它,你可以尝试下面的方法(大量的假设认为IPv4总是排在第一位,但在我所有的实验中,它还没有排在第二位;)

代码语言:javascript
复制
ForEach($NIC in $env:computername) {
    $intIndex = 1
    $NICInfo = Get-WmiObject -ComputerName $env:computername Win32_NetworkAdapterConfiguration | Where-Object {$_.IPAddress -ne $null}
    $caption = $NICInfo.Description
    #Only interested in the first IP Address - the IPv4 Address
    $ipAddress = $NICInfo.IPAddress[0]
    #Only interested in the first IP Subnet - the IPv4 Subnet    
    $ipSubnet = $NICInfo.IpSubnet[0] 
    $ipGateWay = $NICInfo.DefaultIPGateway 
    $macAddress = $NICInfo.MACAddress 
    Write-Host "Interface Name: $caption"
    Write-Host "IP Addresses: $ipAddress" 
    Write-Host "Subnet Mask: $ipSubnet"
    Write-Host "Default Gateway: $ipGateway"
    Write-Host "MAC: $macAddress"
    $intIndex += 1
}

希望这能有所帮助!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17644341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档