I’m trying to list just the IP Address of my Wi-Fi network adapter to be able to detect if it is connected and has an IP address attached to it.
With this by itself it is working…
from subprocess import Popen
stdout, stderr = Popen([
'netsh',
'interface',
'ip',
'show',
'addresses',
'Wi-Fi'
]).communicate()
print(stdout)
Output:
Configuration for interface "Wi-Fi"
DHCP enabled: No
IP Address: 192.168.1.200
Subnet Prefix: 192.168.1.0/24 (mask 255.255.255.0)
Default Gateway: 192.168.1.1
Gateway Metric: 0
InterfaceMetric: 2
But, with this…
from subprocess import Popen
stdout, stderr = Popen([
'netsh',
'interface',
'ip',
'show',
'addresses',
'Wi-Fi',
'|',
'findstr',
'/ir',
'IP Address'
]).communicate()
print(stdout)
with the or |
symbol in the list, it is generating this…
Usage: show addresses [[name=]<string>]
Parameters:
Tag Value
name - The name or index of a specific interface.
Remarks: Displays the IP address configuration for an interface or
interfaces.
The information displayed for this command consists of:
Field Description
----- -----------
DHCP enabled Shows whether the address comes from static or DHCP
configuration.
IP Address Shows the IP address configured for an interface.
Subnet Mask Shows the subnet mask associated with the IP address.
Default Gateway Shows the IP address of a default gateway for the interface.
Gateway Metric Shows the metric for the default gateway shown above.
Only applies if multiple default gateways are configured.
Interface Metric Shows the metric for an interface.
Only applies if multiple interfaces are configured.
Examples:
show addresses "Wired Ethernet Connection"
indicating that I typed in the wrong name of the adapter.
I’ve tried many combinations of the arguments of netsh
in the list without any luck.
Does anyone have any Insight on this?
My best guess at the moment is that Popen doesn’t know how to process the or |
symbol.