By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

VB: Find default gateway and set persistent routes or output to a batch file.

P: 2
I am fairly familiar with scripting dos commands and that's about it. I remember some syntax and whatnot from a few programming classes I've taken but I don't remember any of the modules or functions for VB at all.

Goal:
I need to set persistent routes for 2 ip address on a VPN that has a dynamic gateway each time it connects.

I am almost positive I can't script this with standard dos commands so I am wondering if VB will let me do this and if so how? If not, does anyone know of a way that I can? I am desperate for help here.

This is what the batch file would looks like in case it is any help:

ROUTE delete 10.12.12.96
ROUTE delete 10.22.12.83

ROUTE -p add 10.12.12.96 MASK 255.255.255.255 [dynamicGateway]
ROUTE -p add 10.22.12.83 MASK 255.255.255.255 [dynamicGateway]

If I can't use a function to pull the gateways I know I can output ipconfig to a text file and then possibly pull the gateway from that file if needed.

Thanks so much to anyone who can help.

Jeremy
Apr 18 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 5K+
P: 8,434
I don't know much about the networking area, but at the very least you could have VB process that output text file and either issue the DOS commands or write the batch file dynamically then execute it.

Hopefully you'll be able to find a more elegant solution than that, though.
Apr 19 '07 #2

P: 2
At this point I'm desperate for any solution. Right now I have her running a batch to output the ipconfig to a text file and copying the default gateway to the batch file that sets the persistent routes. It works but it isn't pretty. I just don't remember anything from my VB classes to help myself out i this situation.
Apr 19 '07 #3

Expert 5K+
P: 8,434
At this point I'm desperate for any solution. Right now I have her running a batch to output the ipconfig to a text file and copying the default gateway to the batch file that sets the persistent routes. It works but it isn't pretty. I just don't remember anything from my VB classes to help myself out i this situation.
If you post samples (suitably edited if there's anything confidential) of the IPCONFIG output text file and the batch file, I could throw together a quick little VB program you can use to put the required value into the batch file before you incoke it.
Apr 19 '07 #4

P: 1
if you use it as a batch file you can easily add the route

@echo off
@(color 6A) & (@Title %title%)
@echo please wait...

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

::# Redirect output to a textfile
route add [Destination IP] mask [subnet mask] %DefaultGateway% -p
Apr 4 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.