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.
11friendAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LHT_STCommented:
whats the name of the interface you check when using ipconfig?
11friendAuthor Commented:
'Ethernet Card Local Connection 12' (after translation) /tap-win32 adapter v9/
giltjrCommented:
What VPN client are you using?  Most of them have a setting that says "make this my default route."
Virus Depot: Cyber Crime Becomes Big Business

The rising threat of malware-as-a-service is not one to be overlooked. Malware-as-a-service is growing and easily purchased from a full-service cyber-criminal store in a “Virus Depot” fashion. View our webinar recording to learn how to best defend against these attacks!

11friendAuthor Commented:
OpenVPN client, a regular one /openvpn.net/
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?
11friendAuthor Commented:
94.75.217.236 but the gateway is 10.2.x.x
giltjrCommented:
No, not what the IP address is, what is the software?
11friendAuthor Commented:
I have no idea, it's xerobank how can check this?
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.

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
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
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.
11friendAuthor Commented:
Let's leave it then. It works and it's ok. Thanks again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VPN

From novice to tech pro — start learning today.