Ashwani Singh
Ashwani Singh

Reputation: 966

how to get ipv4 address of particular adapter via batch script in windows 10

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

Upvotes: 3

Views: 5114

Answers (2)

Hackoo
Hackoo

Reputation: 18827

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%"

Upvotes: 2

user7818749
user7818749

Reputation:

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

Upvotes: 4

Related Questions