Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 我想获取默认网关的前3个八位字节_Powershell - Fatal编程技术网

Powershell 我想获取默认网关的前3个八位字节

Powershell 我想获取默认网关的前3个八位字节,powershell,Powershell,这个命令提供了整个ip,比如192.168.1.1 我对192.168.1感兴趣。一些字符串操作可以做到: $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).ne

这个命令提供了整个ip,比如
192.168.1.1


我对
192.168.1感兴趣。

一些字符串操作可以做到:

$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

一些字符串操作可以做到这一点:

$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=(Get-WmiObject -Class Win32_IP4RouteTable | where {'0.0.0.0' -in ( $_.destination, $_.mask)}).nexthop

# method 1
($ip -split "\.")[0..2] -join "."
其他解决方案

$ip=(Get-WmiObject -Class Win32_IP4RouteTable | where {'0.0.0.0' -in ( $_.destination, $_.mask)}).nexthop

# method 1
($ip -split "\.")[0..2] -join "."

无法使用remove,因为有些网关可能类似于10.10.x.y
-replace'\d+$'
$addr.Split('.)[0..2]-join'.
无法使用remove,因为有些网关可能类似于10.10.x.y
-replace'\d+$。
$addr.Split('.[0..2]-join'.