Link to home
Start Free TrialLog in
Avatar of 11friend
11friend

asked on

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.
Avatar of LHT_ST
LHT_ST

whats the name of the interface you check when using ipconfig?
Avatar of 11friend

ASKER

'Ethernet Card Local Connection 12' (after translation) /tap-win32 adapter v9/
Avatar of giltjr
What VPN client are you using?  Most of them have a setting that says "make this my default route."
OpenVPN client, a regular one /openvpn.net/
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?
94.75.217.236 but the gateway is 10.2.x.x
No, not what the IP address is, what is the software?
I have no idea, it's xerobank how can check this?
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.

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
ASKER CERTIFIED SOLUTION
Avatar of giltjr
giltjr
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.
Let's leave it then. It works and it's ok. Thanks again.