Page 1 of 1 1
Topic Options
#158342 - 2006-03-05 03:35 PM Text parsing to "Route Add" with dynamic gateway..?
ScottDavis Offline
Lurker

Registered: 2005-02-11
Posts: 3
Folks,

I want to semi-automate an "Add Route" on one WinXP client.

Let me walk you through it, step by step..?


1) Launch VPN to remote site. VPN interface will be assigned address 10.0.0.123, for example. Assume "Use Default Gateway on Remote Network" is NOT selected.

2) Internal network at remote site is 192.168.21.x/24.

3) I manually add a route, using "Route Add 192.168.21.0 mask 255.255.255.0 10.0.0.123" and I'm happy.



Keeping in mind that 10.0.0.123 is dynamically assigned and often changes, I'm looking to automate step #3.

I can "ipconfig > ipconf.txt", then "grep 10.0.0 ipconf.txt" which returns one line, such as:

IP Address. . . . . . 10.0.0.123


*IF* I could ltrim (or rtrim?) that to output *JUST* 10.0.0.123 in a text file, how can I script the "Route Add 192.168.21.0 mask 255.255.255.0 **INSERT VALUE HERE**" from the file..?



I know what I want to do, but I suck at bashing the code. No attention span.


If there's a more elegant solution than dumping to text, greping that to another text, trimming that text and piping it INTO a script, I'd love to see how it could be done.


So, worst case, if someone could help me:

1) trim the "ipconf.txt" file
and
2) Show me an example of how to use contents of a text file as input into a script

.. I'll be working, despite how ugly it'll be..


Thanks, VM, everyone!

-- Scott.

Top
#158343 - 2006-03-05 03:50 PM Re: Text parsing to "Route Add" with dynamic gateway..?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Break On
$String = 'IP Address. . . . . . 10.0.0.123'
$IP = Split($String,'IP Address. . . . . . ')[1]
$IP ?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158344 - 2006-03-05 03:53 PM Re: Text parsing to "Route Add" with dynamic gateway..?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hee, Les beat me to it but here's my take:

Code:

break on

$output = "c:\ipconf.txt"

shell '%comspec% /c ipconfig | findstr /i "10.0.0" >$output'

$ip = "not found"

if exist($output)
if open(1, $output) = 0
$ip = readline(1)
if $ip
$ip = trim(split($ip,":")[1])
endif
$= close(1)
endif
endif

?"ip=" $ip

exit 0


Top
#158345 - 2006-03-05 03:56 PM Re: Text parsing to "Route Add" with dynamic gateway..?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't know about what you claim IPCONFIG to return, but mine does not return the string you gave as an example.
You don't need to send to to a test file either. You can pipe it back to KiX with one of several pipe UDFs. You also don't need to use GREP when FIND is built in.
Code:
  ipconfig | find "IP Address. . . . . . . . . . . . :"


_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158346 - 2006-03-05 03:59 PM Re: Text parsing to "Route Add" with dynamic gateway..?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Could you not just use the KiX @IPaddressX macro?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158347 - 2006-03-05 04:06 PM Re: Text parsing to "Route Add" with dynamic gateway..?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Shawn,
Do you prefer FINDSTR over FIND?
Would not your method not also return the DG?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158348 - 2006-03-05 04:12 PM Re: Text parsing to "Route Add" with dynamic gateway..?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Findstr is just a habit for me. In terms of the DG - prolly - I was just working off the specification provided.
Top
#158349 - 2006-03-05 04:17 PM Re: Text parsing to "Route Add" with dynamic gateway..?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Thinking though that since it will return only the first occurence of the ip, the DG will be ignored. idk
Top
#158350 - 2006-03-05 04:26 PM Re: Text parsing to "Route Add" with dynamic gateway..?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
$IP = Join(Split(@IPaddress0,' '),'') ;assuming 0 is the one
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158351 - 2006-03-06 03:04 AM Re: Text parsing to "Route Add" with dynamic gateway..?
ScottDavis Offline
Lurker

Registered: 2005-02-11
Posts: 3
Everyone,

I can't thank you enough for taking the time to provide those samples. I think Shawn's sample is what I'm going to end up using.

Best wishes to all of you.

-- Scott.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 837 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.058 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org