英文:
Get IP v4 address
问题
使用以下命令获取IP地址,我已经使用-Match,因为有时它是Ethernet或Ethernet0、Ethernet1,我想要排除所有以127.0.0.1或169*开头的网络适配器,你能帮我实现吗?谢谢。
Get-NetIPAddress -AddressFamily IPv4 | where Interfacealias -Match 'Ethernet'
只获取一个IP,而不是127和169。
英文:
i get the IP address with the following command, i've putted -Match because sometimes it's Ethernet or Ethernet0, Ethernet1, i would like to excluse every network adapteur who come with ip LIke 127.0.0.1 or 169* in my following where, can you help me to do that ? thanks.
Get-NetIPAddress -AddressFamily IPv4 | where Interfacealias -Match 'Ethernet'
get only 1 IP, not 127 and 169
答案1
得分: 2
保留地址空间中的地址,例如本地回环(127.0.0.0/8)和链路本地地址(169.254.0.0/16),将标记为PrefixOrigin: WellKnown
- 您可以使用这个来过滤它们:
$actualAddresses = Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias Ethernet | Where PrefixOrigin -ne WellKnown
如果您只想要第一个可用的结果,请使用Select-Object -First 1
:
$firstActualAddress = Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias Ethernet | Where PrefixOrigin -ne WellKnown | Select-Object -First 1
英文:
Addresses from the reserved parts of the address space - like the localhost loopback (127.0.0.0/8) and link-locals (169.254.0.0/16) - will be marked with PrefixOrigin: WellKnown
- you can use this to filter them out:
$actualAddresses = Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias Ethernet |Where PrefixOrigin -ne WellKnown
If you want only the first available result, use Select-Object -First 1
:
$firstActualAddress = Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias Ethernet |Where PrefixOrigin -ne WellKnown |Select-Object -First 1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论