• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1585
  • Last Modified:

how to obtain a default gateway IP in a batch file?

I'd like to make a batch file that obtains IP number of default gateway that my vpn provider uses. I need it to use it in a command: route change 0.0.0.0 mask 0.0.0.0 'the number'. And I don't want to check it manually with ipconfig/all everytime I switch my vpn on.
0
11friend
Asked:
11friend
  • 7
  • 6
1 Solution
 
LHT_STCommented:
whats the name of the interface you check when using ipconfig?
0
 
11friendAuthor Commented:
'Ethernet Card Local Connection 12' (after translation) /tap-win32 adapter v9/
0
 
giltjrCommented:
What VPN client are you using?  Most of them have a setting that says "make this my default route."
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
11friendAuthor Commented:
OpenVPN client, a regular one /openvpn.net/
0
 
giltjrCommented:
I will need to do more reading, but it looks like OpenVPN client expects the server to tell it what to use as a default gateway.  What is the VPN server?
0
 
11friendAuthor Commented:
94.75.217.236 but the gateway is 10.2.x.x
0
 
giltjrCommented:
No, not what the IP address is, what is the software?
0
 
11friendAuthor Commented:
I have no idea, it's xerobank how can check this?
0
 
giltjrCommented:
You can ask them.

I am assuming that since you want to use this as your default connection once connected you are an empoyee of this company.

If so, they should give you the instructions on how to do this.  

Are you in a department were if changes needed to be made to the server they would do it?

Can you post the output of the command "ipconfig /all" after you connect to the VPN?  I have a script that I should be able to modify for you.

0
 
11friendAuthor Commented:
Here it is. Not in English I'm afraid.
Xerobank is a commercial VPN server.
I just thought there was a simple XP command that extracted that number from ipconfig. I just wanted to create a simple switch that stops your traffic when vpn is off without additional software. I'm not using vpn all the time.
sc.jpg
0
 
giltjrCommented:
You can put the following in a .cmd file and after you connect to the VPN, execute this.


ipconfig | FIND "10.2.0." > %temp%\TEMPIP.txt
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
route add 0.0.0.0 mask 0.0.0.0 %IP%

If this works, you might be able to setup a cmd file that initates the VPN connect and the above stuff.
0
 
11friendAuthor Commented:
Thanks. It works. I'll award you with another 500 points if you create a universal solution (not dependent on a  gateway 'prefix'). Let me know if you you're interested and I'll ask another question.
0
 
giltjrCommented:
Without running the script I provided, can you issue the command:

     netstat -r

from both before and after you connect to the VPN?  After re looking at the output from ipconfig /all it looks like you do have a default gateway set (10.2.0.26) for the VPN tunnel.    You can only really have one default gateway although you can define many.  The one that is the real default gateway will be the one that either has the highest priority (lowest metric number).  If you have two defaults with equal metrics, then the interface that is "bound" 1st is used.

Doing a universal script would be a bit more complicated.  The issue is you would need to know the name of the interface that represents the VPN tunnel, then get all the information related to that interface.  Doing it via a batch file would be very difficult if not impossible (at least for me, I'm not that good).   A VBS script could make it easier, but I don't do VBS.
0
 
11friendAuthor Commented:
Let's leave it then. It works and it's ok. Thanks again.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now