Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Default Gateway from Batch file

I want to return the Default Gateway like i have for the IPv4 but it returns Blank.

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

This is what i have so far but it returns blank, i have tried to alter it but it still returns a blank answer.

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

Any ideas how i can do this. and return the default gateway for a given Computer.

like image 287
MasterT Avatar asked Mar 13 '14 01:03

MasterT


People also ask

How do I find my gateway address using CMD?

In the Command Prompt window, type “ipconfig” and press “Enter/Return” on your keyboard. You will see a lot of information generated in this window. If you scroll up you should see “Default Gateway” with the device's IP address listed to the right of it.

What is default gateway in CMD?

In the "Open:" field, type cmd , and then click OK. This will open the command prompt. At the prompt, enter ipconfig . This will display your network information, including your default gateway.


1 Answers

Here's a WMIC script:

@echo off
for /f "tokens=2,3 delims={,}" %%a in ('"WMIC NICConfig where IPEnabled="True" get DefaultIPGateway /value | find "I" "') do echo IPv4 %%~a IPV6 %%~b
pause
like image 67
foxidrive Avatar answered Oct 14 '22 02:10

foxidrive