3

I am trying to fetch the ipv4 address of the particular adapter(say Ethernet adapter Local Area Connection* 14) is there any command or script to do that in windows 10 . if somebody already had done in past thanks to share it .

Input -- adapter name

Output -- only adapter's ip address

2 Answers 2

4

use netsh

in a batch file

@echo off for /f "tokens=3 delims=: " %%I in ('netsh interface IPv4 show addresses "Ethernet adapter Local Area Connection" ^| findstr /C:"IP Address"') do echo %%I 

if used from command line and not in batch, remove one set of the % in %%I like this.

for /f "tokens=3 delims=: " %I in ('netsh interface IPv4 show addresses "Ethernet adapter Local Area Connection" ^| findstr /C:"IP Address"') do echo %I 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the response but getting no output C:\Users\singh>for /f "tokens=3 delims=: " %I in ('netsh interface IPv4 show addresses "Ethernet adapter Local Area Connection* 14" ^| findstr /C:"IP Address"') do echo %I C:\Users\singh>
you need to get the correct names. from cmd, do netsh interface IPv4 show addresses which will show all. Then ensure you select a valid adapter name, usually they show as Configuration for interface "VMware Network Adapter VMnet8" where you will use only what is in the double quotes, i.e. "VMware Network Adapter VMnet8"
2

You can give a try with this batch script to get :

  1. Private LAN IP (ipv4)

  2. External Public IP

  3. MAC Address


@echo off Title Get (LAN ,Public) (IP) and MAC Addresses by Hackoo 2017 mode con cols=80 lines=5 & Color 9E echo( & echo( echo Please Wait a While ... Searching for (LAN ,Public)(IP) and MAC addresses ... Set "LogFile=%~dpn0.txt" @for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do ( set "LAN_IP=%%a" ) for /f "tokens=2 delims=: " %%A in ( 'nslookup myip.opendns.com. resolver1.opendns.com 2^>NUL^|find "Address:"' ) Do set ExtIP=%%A @For /f %%a in ('getmac /NH /FO Table') do ( @For /f %%b in ('echo %%a') do ( If /I NOT "%%b"=="N/A" ( Set "MY_MAC=%%b" ) ) ) Cls echo( echo My Private LAN IP : %LAN_IP% echo My External Public IP : %ExtIP% echo MAC Addres : %MY_MAC% ( echo My Private LAN IP : %LAN_IP% echo My External Public IP : %ExtIP% echo MAC Address : %MY_MAC% )>"%LogFile%" Timeout /T 5 /NoBreak>nul Start "" "%LogFile%" 

2 Comments

Thanks for sharing
In case you have (also) an external IPv6 address, nslookup myip.opendns.com. resolver1.opendns.com will return this and the batch cut's off at the first colon in the IPv6 address, if you change to tokens=1* and set ExtIP=%%B it is retained. See my answer to get IPv4 with PowerShell.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.