Reputation: 157
I have more than one adapter in my system and I want to know the IP of particular adapter. Is it possible through a command in Windows, in Linux it's easy? Or any other way?
Upvotes: 14
Views: 42812
Reputation: 45
A much cleaner option
First for straight output
Get-NetIPAddress -InterfaceIndex (Get-NetRoute -RouteMetric 0).ifindex | ft
Then if you want only the IP
Get-NetIPAddress -InterfaceIndex (Get-NetRoute -RouteMetric 0).ifindex | fl IPAddress
And if you specifically looking for the IPV4 or IPV6 address
Get-NetIPAddress -InterfaceIndex (Get-NetRoute -RouteMetric 0).ifindex -AddressFamily IPv4| fl IPAddress
Get-NetIPAddress -InterfaceIndex (Get-NetRoute -RouteMetric 0).ifindex -AddressFamily IPv6| fl IPAddress
Upvotes: 0
Reputation: 4333
With Powershell
Get-NetIpInterface
ifIndex InterfaceAlias AddressFamily NlMtu(Bytes) InterfaceMetric Dhcp ConnectionState PolicyStore
------- -------------- ------------- ------------ --------------- ---- --------------- -----------
56 vEthernet (WSL) IPv6 1500 15 Enabled Connected ActiveStore
17 vEthernet (Default Switch) IPv6 1500 15 Enabled Connected ActiveStore
7 Local Area Connection* 2 IPv6 1500 25 Enabled Disconnected ActiveStore
21 Ethernet 2 IPv6 1348 25 Enabled Connected ActiveStore
26 Local Area Connection* 1 IPv6 1500 25 Disabled Disconnected ActiveStore
25 Ethernet IPv6 1500 5 Enabled Disconnected ActiveStore
12 Wi-Fi IPv6 1500 35 Enabled Connected ActiveStore
1 Loopback Pseudo-Interface 1 IPv6 4294967295 75 Disabled Connected ActiveStore
56 vEthernet (WSL) IPv4 1500 15 Disabled Connected ActiveStore
17 vEthernet (Default Switch) IPv4 1500 15 Disabled Connected ActiveStore
7 Local Area Connection* 2 IPv4 1500 25 Enabled Disconnected ActiveStore
21 Ethernet 2 IPv4 1348 1 Disabled Connected ActiveStore
26 Local Area Connection* 1 IPv4 1500 25 Enabled Disconnected ActiveStore
25 Ethernet IPv4 1500 5 Enabled Disconnected ActiveStore
12 Wi-Fi IPv4 1500 35 Enabled Connected ActiveStore
1 Loopback Pseudo-Interface 1 IPv4 4294967295 75 Disabled Connected ActiveStore
Identify your interface and note the ifIndex and then run
Get-NetIpAddress -AddressFamily IPv4 -InterfaceIndex 21|findstr IPAddress
IPAddress : 172.55.23.43
To get the IPv4 address.
Upvotes: 0
Reputation: 2173
Here's how I was able to get my IP Address for a specific network adapter:
for /f "tokens=3 delims=: " %i in ('netsh interface ip show config name^="Ethernet" ^| findstr "IP Address"') do echo Your IP Address is: %i
For an explanation of how this works, see my related answer here: https://stackoverflow.com/a/59004409/2684661
Upvotes: 2
Reputation: 60230
The following will let you specify an adapter (something ipconfig doesn't appear to do):
netsh interface ip show config name="Local Area Connection"
You can add | findstr "IP Address"
to the end of that command to only show the IP address line.
Upvotes: 36