Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Please see below ipconfig output in windows.

C:>ipconfig

Windows IP Configuration


Ethernet adapter Local Area Connection 11:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::4149:4c25:692d:dfec%91
   IPv4 Address. . . . . . . . . . . : 10.252.26.84
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Wireless LAN adapter Wireless Network Connection 15:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Local Area Connection 10:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Wireless Network Connection 14:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::79a2:afc8:7cd0:79ac%72
   IPv4 Address. . . . . . . . . . . : 192.168.10.9
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.10.1

I want to find the Default Gateway for Wireless Network Connection 14 in a bat file then store that in a varient to use later

I understand I can "findstr" but I have no idea how to get the default gateway of that NIC.

Thanks!

share|improve this question
    
Is it always connection 14? Or is it always the Wireless nic? Do you have any constants? –  RobW Nov 9 '11 at 16:17
add comment

3 Answers

Try something along the lines of:

@For /f "tokens=3" %%* in (
    'route.exe print ^|findstr "\<0.0.0.0\>"'
) Do @Set "DefaultGateway=%%*"

You should then be able to use %DefaultGateway% as a variable.

Source

share|improve this answer
1  
#Naozumi,thanks for your reply, but it is not default route related. just want to get the gateway of the adapter. it may not same as the "route print" printed, for example, a VPN case –  K. C Nov 3 '11 at 16:23
add comment

Verify the interface name with:

netsh interface ip show address

and try something like this:

@echo off

for /f "tokens=2 delims=:" %%g in ('netsh interface ip show address 
"Wireless Network Connection 14" ^| findstr "Default"') do 
set DefaultGateway=%%g
echo %DefaultGateway%
pause
share|improve this answer
add comment

This should get it:

wmic nicconfig where "description like '%wireless%'" get caption, defaultipgateway
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.