2

I want to fetch IP address, subnet, gateway and DNS servers from ipconfig and store in a variable using bash script. I have created below script but it is not fetching dns servers(below XXXX and YYYY) in separate variables.

                                  `DNS Servers . . . . . . . . . . . : XXXX
                                                                       YYYY`

echo IPAddress is:
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IPv4"') do set ip=%%b
set ip=%ip:~1%
echo %ip%

for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "Subnet"') do set sub=%%b
set sub=%sub:~1%
echo Subnet is:
echo %sub%

for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "Default"') do set gate=%%b
set gate=%gate:~1%
echo Gateway is:
echo %gate%

0

1 Answer 1

0

Refer to this : Get current DNS server used by using Batch code?

@echo off
rem clean variable
set "ip="
rem search data
for /f "tokens=2 delims=:" %%f in ('echo exit^|nslookup 2^>nul') do ( @echo %%f & set "ip=%%f" )
rem remove spaces from variable
set "ip=%ip: =%"
echo DNS_ip = %ip%
pause

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .