5

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!

K. C
  • 163
  • 1
  • 1
  • 5
  • Is it always connection 14? Or is it always the Wireless nic? Do you have any constants? – RobW Nov 09 '11 at 16:17

3 Answers3

5

This should get it:

wmic nicconfig where "description like '%wireless%'" get caption, defaultipgateway
RobW
  • 2,766
  • 1
  • 17
  • 22
4

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
quanta
  • 50,327
  • 19
  • 152
  • 213
1

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

Naozumi
  • 138
  • 9
  • 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 03 '11 at 16:23