Taperssection.com

Gear / Technical Help => Post-Processing, Computer / Streaming / Internet Devices & Related Activity => Topic started by: fozzy on March 12, 2010, 02:10:59 PM

Title: Any batch scripting gurus out there?
Post by: fozzy on March 12, 2010, 02:10:59 PM
Any ideas how to simplify/clean this up.  Ideally i would not like to use the tmp file

 @echo off
 (for /F "tokens=2,3,* delims=:" %%i IN ('ipconfig')do (@echo %%i | find "10.253") ) > ip.txt
 set /p pptpip=<ip.txt
 route add x.real.ip.0 mask 255.255.255.0 %pptpip%
 route delete X.X.0.0 mask 255.255.0.0 %pptpip%
 del ip.txt


edit:  I am limited to whatever is available on windows xp.  I know this could be a one liner in perl or bash or any real scripting language
Title: Re: Any batch scripting gurus out there?
Post by: Shadow_7 on March 12, 2010, 02:43:13 PM
There is a version of bash that runs in windows.  Obviously not installed by default though.

You might try | instead of >.  pipe instead of redirect.  while read VAR (in bash on the back side).  Not sure of the windows version.  And it's obviously beefed up a bit since I last used it.  Does ";" signify next command in DOS like it does in bash (might be one option to make it a one liner of sorts (big fat bloated one liner))?  It's been soo long since I've done anything serious in windows.  It's more of a gaming platform IMO.  (and not that good of one)
Title: Re: Any batch scripting gurus out there?
Post by: H₂O on March 12, 2010, 04:26:11 PM
what exactly are you trying to do?
 
ipconfig provides the ip addresses
you pull off the one that begins the one that begins with 10.253.X.X?
route add real IP class C subnet to pulled IP
route delete real IP class B subnet to pulled IP
 
What is the output of ipconfig
What is the routing table before
What is the routing table after
 
 (you can mod the output with bogus IPs)
Title: Re: Any batch scripting gurus out there?
Post by: H₂O on March 12, 2010, 05:49:08 PM
Here's one option - note it could be a little cleaner then this:
 
@echo off
for /f "tokens=2,3,* delims=:" %%i in ('ipconfig') do for /f %%j in ('echo %%i ^| find "10.253"') do (
  route add x.real.ip.0 mask 255.255.255.0 %%j
  route delete x.x.0.0 mask 255.255.0.0 %%j
)
Title: Re: Any batch scripting gurus out there?
Post by: H₂O on March 12, 2010, 05:56:25 PM
Slightly cleaner:
@echo off
for /f "tokens=2 delims=:" %%i in ('ipconfig ^| find "Address" ^| find "10.253"') do (
  route add x.real.ip.0 mask 255.255.255.0 %%i
  route delete x.x.0.0 mask 255.255.0.0 %%i
)
Title: Re: Any batch scripting gurus out there?
Post by: fozzy on March 12, 2010, 09:17:08 PM
thanks i will try those out monday

the situation is that a customer pptp connection is polluting the routing table on a user workstations and also does not push the proper route needed to access.  they provided 10 pages of instruction(that don't work reliably) of what the user is supposed to do every time they need to use the VPN.  the main flaw is that their solution relies on DNS caching, user figuring out their vpn ip, adding routes and also managing to remember another password. 

trying to eliminate and simplify as many steps as possible.

Title: Re: Any batch scripting gurus out there?
Post by: H₂O on March 12, 2010, 09:42:36 PM
Batch sucks! 
 
For Windows, I would definitely suggest getting familar with wsh (Windows Scripting Host - MS jscript/vbscript by default) - I prefer jscript but vbscript is the only option in some cases due to it's array structures.  At least you can use Regular Expressions in either though.
Title: Re: Any batch scripting gurus out there?
Post by: phanophish on March 16, 2010, 01:20:40 AM
I feel like a ran across a similar issue in the past and worked around it my adjusting the binding order of network devices so that the VPN connection did not become the default route for any traffic except that down the tunnel.  I think you can also prevent the Pc from learning dynamic routes in certain scopes.  Might be a easier trick to manage than scripting it......
Title: Re: Any batch scripting gurus out there?
Post by: phanophish on May 20, 2010, 11:02:54 AM
Take a look at this...  My gut is that by adjusting the interface metrics you can avoid the issue i and not need to alter/mess with static routes.

http://support.microsoft.com/kb/894564

Title: Re: Any batch scripting gurus out there?
Post by: Chilly Brioschi on May 26, 2010, 02:12:14 AM
Do batch scripts still work?

Would this help?:


C:\Bart.Ender>netsh /?

Usage: netsh [-a AliasFile] [-c Context] [-r RemoteMachine] [-u [DomainName\]Use
rName] [-p Password | *]
             [Command | -f ScriptFile]

The following commands are available:

Commands in this context:
?              - Displays a list of commands.
add            - Adds a configuration entry to a list of entries.
advfirewall    - Changes to the `netsh advfirewall' context.
bridge         - Changes to the `netsh bridge' context.
delete         - Deletes a configuration entry from a list of entries.
dhcpclient     - Changes to the `netsh dhcpclient' context.
dump           - Displays a configuration script.
exec           - Runs a script file.
firewall       - Changes to the `netsh firewall' context.
help           - Displays a list of commands.
http           - Changes to the `netsh http' context.
interface      - Changes to the `netsh interface' context.
ipsec          - Changes to the `netsh ipsec' context.
lan            - Changes to the `netsh lan' context.
nap            - Changes to the `netsh nap' context.
netio          - Changes to the `netsh netio' context.
p2p            - Changes to the `netsh p2p' context.
ras            - Changes to the `netsh ras' context.
rpc            - Changes to the `netsh rpc' context.
set            - Updates configuration settings.
show           - Displays information.
wcn            - Changes to the `netsh wcn' context.
winhttp        - Changes to the `netsh winhttp' context.
winsock        - Changes to the `netsh winsock' context.
wlan           - Changes to the `netsh wlan' context.

The following sub-contexts are available:
 advfirewall bridge dhcpclient firewall http interface ipsec lan nap netio p2p r
as rpc wcn winhttp winsock wlan

To view help for a command, type the command, followed by a space, and then
 type ?.

C:\Bart.Ender>
Title: Re: Any batch scripting gurus out there?
Post by: Gordon on July 01, 2010, 03:59:27 PM
I got a VERY easy one for y'all ;)

this is for class so it's very simple.  basically I'm supposed to write a batch file that shows the dir of a folder (contacts) on g drive, and then the contents of one of the textfiles (people.txt) within.  I got it to work with something like

dir g:\contacts
type g:\contacts\people.txt


the problem is when it runs the prompt is directly beside the contents of the people.txt.  like this

testing testingC:\>

here is a screen shot.

(http://img.photobucket.com/albums/v488/datdork/untitled-6.jpg)




I know I can put the type command before the dir command in the bat and it runs correctly but it's supposed to be in the order I have it (dir then type).

Title: Re: Any batch scripting gurus out there?
Post by: Gordon on July 01, 2010, 10:50:49 PM
got that one figured out.  got more if anyone feels like helping ;)
Title: Re: Any batch scripting gurus out there?
Post by: Shadow_7 on July 02, 2010, 10:57:00 AM
@echo off

the @ prevents the echo off from showing up.
Title: Re: Any batch scripting gurus out there?
Post by: H₂O on July 06, 2010, 11:54:13 PM
Do batch scripts still work?

Would this help?:


C:\Bart.Ender>netsh /?

Usage: netsh [-a AliasFile] [-c Context] [-r RemoteMachine] [-u [DomainName\]Use
rName] [-p Password | *]
             [Command | -f ScriptFile]

The following commands are available:

Commands in this context:
?              - Displays a list of commands.
add            - Adds a configuration entry to a list of entries.
advfirewall    - Changes to the `netsh advfirewall' context.
bridge         - Changes to the `netsh bridge' context.
delete         - Deletes a configuration entry from a list of entries.
dhcpclient     - Changes to the `netsh dhcpclient' context.
dump           - Displays a configuration script.
exec           - Runs a script file.
firewall       - Changes to the `netsh firewall' context.
help           - Displays a list of commands.
http           - Changes to the `netsh http' context.
interface      - Changes to the `netsh interface' context.
ipsec          - Changes to the `netsh ipsec' context.
lan            - Changes to the `netsh lan' context.
nap            - Changes to the `netsh nap' context.
netio          - Changes to the `netsh netio' context.
p2p            - Changes to the `netsh p2p' context.
ras            - Changes to the `netsh ras' context.
rpc            - Changes to the `netsh rpc' context.
set            - Updates configuration settings.
show           - Displays information.
wcn            - Changes to the `netsh wcn' context.
winhttp        - Changes to the `netsh winhttp' context.
winsock        - Changes to the `netsh winsock' context.
wlan           - Changes to the `netsh wlan' context.

The following sub-contexts are available:
 advfirewall bridge dhcpclient firewall http interface ipsec lan nap netio p2p r
as rpc wcn winhttp winsock wlan

To view help for a command, type the command, followed by a space, and then
 type ?.

C:\Bart.Ender>



netsh is a good utility but be careful with netsh as different versions of windows use slightly different syntax