Become a Site Supporter and Never see Ads again!

Author Topic: Any batch scripting gurus out there?  (Read 3434 times)

0 Members and 1 Guest are viewing this topic.

Offline fozzy

  • Trade Count: (2)
  • Needs to get out more...
  • *****
  • Posts: 3810
  • Gender: Male
  • move along, nothing much to see here
Any batch scripting gurus out there?
« 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
« Last Edit: March 12, 2010, 02:31:36 PM by fozzy »
MK 4V > KCY 250/5 Ig (KS 10I)  > VST62IUg > 722

Offline Shadow_7

  • Trade Count: (0)
  • Taperssection Member
  • ***
  • Posts: 310
Re: Any batch scripting gurus out there?
« Reply #1 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)

Offline H₂O

  • Trade Count: (28)
  • Needs to get out more...
  • *****
  • Posts: 5745
  • Gender: Male
Re: Any batch scripting gurus out there?
« Reply #2 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)
Music can at the least least explain you and at the most expand you
LMA Recordings

List

Offline H₂O

  • Trade Count: (28)
  • Needs to get out more...
  • *****
  • Posts: 5745
  • Gender: Male
Re: Any batch scripting gurus out there?
« Reply #3 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
)
Music can at the least least explain you and at the most expand you
LMA Recordings

List

Offline H₂O

  • Trade Count: (28)
  • Needs to get out more...
  • *****
  • Posts: 5745
  • Gender: Male
Re: Any batch scripting gurus out there?
« Reply #4 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
)
Music can at the least least explain you and at the most expand you
LMA Recordings

List

Offline fozzy

  • Trade Count: (2)
  • Needs to get out more...
  • *****
  • Posts: 3810
  • Gender: Male
  • move along, nothing much to see here
Re: Any batch scripting gurus out there?
« Reply #5 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.

MK 4V > KCY 250/5 Ig (KS 10I)  > VST62IUg > 722

Offline H₂O

  • Trade Count: (28)
  • Needs to get out more...
  • *****
  • Posts: 5745
  • Gender: Male
Re: Any batch scripting gurus out there?
« Reply #6 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.
Music can at the least least explain you and at the most expand you
LMA Recordings

List

Offline phanophish

  • Trade Count: (2)
  • Needs to get out more...
  • *****
  • Posts: 2128
  • Gender: Male
    • ImageLume Photography
Re: Any batch scripting gurus out there?
« Reply #7 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......
______________________________________________
Audio: MBHO 603/KA200N or AKG C2000B>Edirol R44
http://www.archive.org/bookmarks/phanophish

Photo:  Nikon D300, D200, 35mm f/1.8,  50mm f/1.4, 85mm f/1.8, Nikon 17-55 f/2.8, Sigma 18-50/2.8 Macro, 18-70 f/4.5-5.6, 24-120 f/3.5-5.6 VR, Sigma 10-20 f4-5.6, Nikon 70-200 f/2.8VR, SB-800

Jake: What's this?
Elwood: What?
Jake: This car. This stupid car. Where's the Cadillac? The Caddy? Where's the Caddy?
Elwood: The what?
Jake: The Cadillac we used to have. The Blues Mobile!
Elwood: I traded it.
Jake: You traded the Blues Mobile for this?
Elwood: No. For a microphone.
Jake: A microphone? Okay I can see that.

Offline phanophish

  • Trade Count: (2)
  • Needs to get out more...
  • *****
  • Posts: 2128
  • Gender: Male
    • ImageLume Photography
Re: Any batch scripting gurus out there?
« Reply #8 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

______________________________________________
Audio: MBHO 603/KA200N or AKG C2000B>Edirol R44
http://www.archive.org/bookmarks/phanophish

Photo:  Nikon D300, D200, 35mm f/1.8,  50mm f/1.4, 85mm f/1.8, Nikon 17-55 f/2.8, Sigma 18-50/2.8 Macro, 18-70 f/4.5-5.6, 24-120 f/3.5-5.6 VR, Sigma 10-20 f4-5.6, Nikon 70-200 f/2.8VR, SB-800

Jake: What's this?
Elwood: What?
Jake: This car. This stupid car. Where's the Cadillac? The Caddy? Where's the Caddy?
Elwood: The what?
Jake: The Cadillac we used to have. The Blues Mobile!
Elwood: I traded it.
Jake: You traded the Blues Mobile for this?
Elwood: No. For a microphone.
Jake: A microphone? Okay I can see that.

Offline Chilly Brioschi

  • The fool doth think he is wise, but the wise man knows himself to be a fool.
  • Trade Count: (0)
  • Needs to get out more...
  • *****
  • Posts: 15467
  • Gender: Male
  • Waiting for the next cladogenetic event, or Godot
    • Oceana North America
Re: Any batch scripting gurus out there?
« Reply #9 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>
"Peace is for everyone"
        - Norah Jones

"Music is the drug that won't kill you"
         - Fran Lebowitz

Offline Gordon

  • Trade Count: (22)
  • Needs to get out more...
  • *****
  • Posts: 11786
  • Gender: Male
    • my list
Re: Any batch scripting gurus out there?
« Reply #10 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.






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

Microtech Gefell M20 or M21 > Nbob actives > Naiant PFA > Sound Devices MixPre-6 II @ 32/48

https://archive.org/details/fav-gordonlw

https://archive.org/details/teamdirtysouth

Offline Gordon

  • Trade Count: (22)
  • Needs to get out more...
  • *****
  • Posts: 11786
  • Gender: Male
    • my list
Re: Any batch scripting gurus out there?
« Reply #11 on: July 01, 2010, 10:50:49 PM »
got that one figured out.  got more if anyone feels like helping ;)
Microtech Gefell M20 or M21 > Nbob actives > Naiant PFA > Sound Devices MixPre-6 II @ 32/48

https://archive.org/details/fav-gordonlw

https://archive.org/details/teamdirtysouth

Offline Shadow_7

  • Trade Count: (0)
  • Taperssection Member
  • ***
  • Posts: 310
Re: Any batch scripting gurus out there?
« Reply #12 on: July 02, 2010, 10:57:00 AM »
@echo off

the @ prevents the echo off from showing up.

Offline H₂O

  • Trade Count: (28)
  • Needs to get out more...
  • *****
  • Posts: 5745
  • Gender: Male
Re: Any batch scripting gurus out there?
« Reply #13 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

Music can at the least least explain you and at the most expand you
LMA Recordings

List

 

RSS | Mobile
Page created in 0.088 seconds with 39 queries.
© 2002-2024 Taperssection.com
Powered by SMF