@@ -8,6 +8,10 @@ loopbacks are ignored.
8
8
. PARAMETER Addresses
9
9
Return a @(list) of addresses
10
10
11
+ . PARAMETER bound
12
+ Show only interfaces that are bound to a known IP address, hiding disconnected virtual
13
+ or VPN interfaces.
14
+
11
15
. PARAMETER Preferred
12
16
Only return the preferred network address without report bells and whistles.
13
17
@@ -27,6 +31,7 @@ using namespace System.Net.NetworkInformation
27
31
param (
28
32
[switch ] $preferred , # just return the preferred address
29
33
[switch ] $addresses , # return a list of host addresses
34
+ [switch ] $bound , # show only interfaces bound to an IP address
30
35
[switch ] $wiFi # show detailed WiFi profiles
31
36
)
32
37
@@ -129,44 +134,47 @@ Begin
129
134
| where { $_.Address.AddressFamily -eq ' InterNetwork' } `
130
135
| select - first 1 - ExpandProperty Address
131
136
132
- $item.DNSServer = $props.DnsAddresses `
133
- | where { $_.AddressFamily -eq ' InterNetwork' } `
134
- | select - first 1 - ExpandProperty IPAddressToString
135
-
136
- $item.Gateway = $props.GatewayAddresses `
137
- | where { $_.Address.AddressFamily -eq ' InterNetwork' } `
138
- | select - first 1 - ExpandProperty Address
137
+ if ($item.Address -or -not $bound )
138
+ {
139
+ $item.DNSServer = $props.DnsAddresses `
140
+ | where { $_.AddressFamily -eq ' InterNetwork' } `
141
+ | select - first 1 - ExpandProperty IPAddressToString
139
142
140
- $stats = $_ .GetIPv4Statistics () | Select - first 1
141
- $item .BytesReceived = $stats .BytesReceived
142
- $item .BytesSent = $stats .BytesSent
143
+ $item .Gateway = $props .GatewayAddresses `
144
+ | where { $_ .Address.AddressFamily -eq ' InterNetwork ' } `
145
+ | select - first 1 - ExpandProperty Address
143
146
144
- $item.Description = $_.Name + ' , ' + $_.Description
145
- $item.DnsSuffix = $props.DnsSuffix
146
- if (! [String ]::IsNullOrWhiteSpace($item.DnsSuffix ))
147
- {
148
- $item.Description += (' , ' + $item.DnsSuffix )
149
- }
147
+ $stats = $_.GetIPv4Statistics () | Select - first 1
148
+ $item.BytesReceived = $stats.BytesReceived
149
+ $item.BytesSent = $stats.BytesSent
150
150
151
- if ($item.Type.ToString ().StartsWith(' Wireless' ) -and $SSID -and ($item.BytesReceived -gt 0 ))
152
- {
153
- $item.Description = (' , ' + $SSID )
154
- }
151
+ $item.Description = $_.Name + ' , ' + $_.Description
152
+ $item.DnsSuffix = $props.DnsSuffix
153
+ if (! [String ]::IsNullOrWhiteSpace($item.DnsSuffix ))
154
+ {
155
+ $item.Description += (' , ' + $item.DnsSuffix )
156
+ }
155
157
156
- if (($item.Status -eq ' Up' ) -and $item.Address -and ($item.BytesReceived -gt 0 ))
157
- {
158
- if (! $preferred )
158
+ if ($item.Type.ToString ().StartsWith(' Wireless' ) -and $SSID -and ($item.BytesReceived -gt 0 ))
159
159
{
160
- $preferred = $item
160
+ $item .Description = ( ' , ' + $SSID )
161
161
}
162
162
163
- if (! $preffered .SSID )
163
+ if (( $item .Status -eq ' Up ' ) -and $item .Address -and ( $item .BytesReceived -gt 0 ) )
164
164
{
165
- $preferred.SSID = $SSID
165
+ if (! $preferred )
166
+ {
167
+ $preferred = $item
168
+ }
169
+
170
+ if (! $preffered.SSID )
171
+ {
172
+ $preferred.SSID = $SSID
173
+ }
166
174
}
167
- }
168
175
169
- $items += $item
176
+ $items += $item
177
+ }
170
178
}
171
179
}
172
180
}
@@ -262,6 +270,9 @@ Begin
262
270
263
271
function ShowWiFiProfiles
264
272
{
273
+ Write-Host
274
+ Write-Host ' ... fetching WiFi profiles' - ForegroundColor DarkGray - NoNewline
275
+
265
276
$path = Join-Path $env: temp ' wxpx'
266
277
if (Test-Path $path )
267
278
{
0 commit comments