$g = (Get-WmiObject -Class Win32_IP4RouteTable |
where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0'} |
Sort-Object metric1 |
select nexthop, metric1, interfaceindex).nexthop
这个命令给了我整个ip,比如192.168.1.1
。
我对192.168.1.
感兴趣。
答案 0 :(得分:3)
一些字符串操作会这样做:
<button type="file" ngf-select="onLoad($file, $invalidFiles)"
accept="image/*" ngf-max-height="1000" ngf-max-size="1MB">
Select File
</button>
答案 1 :(得分:2)
$ip=(Get-WmiObject -Class Win32_IP4RouteTable | where {'0.0.0.0' -in ( $_.destination, $_.mask)}).nexthop
# method 1
($ip -split "\.")[0..2] -join "."
答案 2 :(得分:0)
其他解决方案
$template=@"
{SubIP*:0.0.0}.0
{SubIP*:255.253.255}.255
"@
Get-WmiObject -Class Win32_IP4RouteTable |
where {'0.0.0.0' -in ( $_.destination, $_.mask)} |
%{ConvertFrom-String -TemplateContent $template -InputObject $_.nexthop}