Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-13-2015, 05:43 AM
e2script e2script is offline
Registered User
 
Join Date: Sep 2014
Posts: 34
Changing selected text before searching

Hi,

Sorry for the badly worded title.

I am running the script described in 4.1 (Performing a Web Search with Selected Text) in this .pdf:
https://www.vandyke.com/support/tips...essentials.pdf

I have modified the script a little bit and I am using the script to search for the OUI vendor over at aruljohn.com/mac.pl

So I have replaced the following:
Code:
' Now search on Google for the information.
g_strSearchBase = "http://www.google.com/search?hl=en&q="
with:
Code:
' Now search on Aruljohn for the information.
g_strSearchBase = "http://aruljohn.com/mac/"
The problem is that the Aruljohn page will only accept a format of AABBCCDDEEFF.

Aruljohn will accept the following: AABBCCDDEEFF
Aruljohn will not accept the following: AA:BB:CC:DD:EE:FF or AABB.CCDD.EEFF

If I copy a MAC-address from an extreme-switch or juniper-router the format will be AA:BB:CC:DD:EE:FF
If I copy a MAC-address from a cisco-router/switch the format will be AABB.CCDD.EEFF

What I want the script to do, before searching for the MAC-address on the Aruljohn page, is to remove the ":" and "." so that Aruljohn will accept the format.

How do I fix this?

Best regards,
e2script
Reply With Quote
  #2  
Old 04-13-2015, 01:04 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi e2script,

You could use the VBScript Replace() function to remove the undesired characters.

Below are 2 examples that expect you have already created a variable with just the MAC:
strMac = Replace(strMac, ":", "")
strMac = Replace(strMac, ".", "")
Does this help?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730

Last edited by rtb; 04-15-2015 at 08:03 AM.
Reply With Quote
  #3  
Old 04-14-2015, 07:08 AM
e2script e2script is offline
Registered User
 
Join Date: Sep 2014
Posts: 34
I think I get the idea of what you're saying, but I don't know how to do it in the script.

Script looks like this:
Code:
# $language = "VBScript"
# $interface = "1.0"

Sub Main()
        strSelection = Trim(crt.Screen.Selection)

	g_strSearchBase = "http://aruljohn.com/mac/"

  	Set g_shell = CreateObject("WScript.Shell")

	If strSelection = "" Then
		Exit Sub
	Else
		g_shell.Run chr(34) & g_strSearchBase & strSelection & chr(34)
		End If
End Sub
How would you execute it based on the script above?

Last edited by e2script; 04-14-2015 at 07:10 AM. Reason: Spelling error
Reply With Quote
  #4  
Old 04-14-2015, 08:59 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi e2script,

In the example I offered, you would replace strMac with strSelection. For example:
strSelection = Trim(crt.Screen.Selection)
strSelection = Replace(strSelection, ":", "")
strSelection = Replace(strSelection, ".", "")
g_strSearchBase = "http://aruljohn.com/mac/"
Does this help you accomplish your goal?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730

Last edited by rtb; 04-15-2015 at 08:03 AM. Reason: Making solution more clear.
Reply With Quote
  #5  
Old 04-15-2015, 12:59 AM
e2script e2script is offline
Registered User
 
Join Date: Sep 2014
Posts: 34
Hi Todd,

That's funny because that's exactly what I tried after your first post, but I received an error message so I figured that I did something wrong.
I tried again now and I'm still receiving the same error message.

Error looks like this:
Quote:
Microsoft VBScript runtime error

Error: Wrong number of arguments or invalid property assignment: 'Replace'
File: <file-path>\<script-name>.vbs
Line: 30
Line 30 is referring to strSelection = Replace(strSelection, ":")

I copied your exact lines
Code:
strSelection = Replace(strSelection, ":")
strSelection = Replace(strSelection, ".")
And placed them in the script between strSelection = Trim(crt.Screen.Selection) and g_strSearchBase = "http://aruljohn.com/mac/" like you suggested.

Any input on how to fix this?
Thanks for your help so far.
Reply With Quote
  #6  
Old 04-15-2015, 01:20 AM
e2script e2script is offline
Registered User
 
Join Date: Sep 2014
Posts: 34
I Googled and I found the answer.
Here's what I ended up with:
Code:
strSelection = Replace(strSelection, ":", "")
strSelection = Replace(strSelection, ".", "")
So I'm guessing why it failed earlier is because the script didn't know what to replace ":" and "." with, but now I've told it to replace it with "blanks".

I found out that Aruljohn only accepts MAC's written in uppercase so I aslo added the following line at the bottom.
Code:
strSelection = UCase(strSelection)
Thank you for your help and for pointing me in the right direction
Reply With Quote
  #7  
Old 04-15-2015, 08:05 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi e2script,

You are correct. I made a mistake. I have edited what I first suggested so that it is correct.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #8  
Old 04-27-2015, 03:18 AM
e2script e2script is offline
Registered User
 
Join Date: Sep 2014
Posts: 34
I have now encountered a new problem similar to the one we have fixed earlier in this thread.
I'm guessing that this new problem also can be solved using the replace method.

What I want the new script to perform is the following:
When I copy something to the clipboard from an external source (external as in outside of the SecureCRT terminal window) I want the script to modify the clipboard content before pasting it in the SecureCRT terminal window.

For you to better understand the problem at hand I'm going to describe what I'm going to use it for:
- I use a system that is mirroring router configuration and displaying it in a GUI
- In that GUI there is a text field displaying certain values. Let's use the following value as an example: 123.456
- The problem occurs when I want to log on to a router using SecureCRT to change the configuration on the router, the router doesn't understand 123.456, it only understands 123 unit 456

Example of how the script is going to be used:
- I copy 123.456 to the clipboard from an external source.
- Then I run a script in SecureCRT changing 123.456 to 123 unit 456 before the script pastes the output in the SecureCRT terminal window.

What is the best way to accomplish this?
Reply With Quote
  #9  
Old 04-27-2015, 10:24 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi e2script,

Assuming you have already copied the 123.456 text into the clipboard, you'd click a button you've mapped into SecureCRT to run a script to do the pasting for you after modification.

Since you're new at this (and there may be others out there that are new to these concepts as well), here's a step-by-step explanation of what you'll want to do:
  1. Transfer the text from the clipboard into a variable that you can use. For example:
    PHP Code:
    strText crt.Clipboard.Text 
  2. Use the VBScript Replace() built-in function to replace the '.' with ' unit ', as you explained. For example.
    PHP Code:
    strText Replace(strText"."" unit "
  3. Use crt.Screen.Send to transmit the modified value to the remote machine. For example
    PHP Code:
    crt.Screen.Send strText 

If I understand what you're trying to accomplish, it doesn't have to be any more complicated than that.

If you have enough courage, you can even combine those three lines of code into a single line that looks like this:
PHP Code:
crt.Screen.Send Replace(crt.Clipboard.Text"."" unit "
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730

Last edited by rtb; 04-27-2015 at 03:30 PM.
Reply With Quote
  #10  
Old 05-06-2015, 03:34 AM
e2script e2script is offline
Registered User
 
Join Date: Sep 2014
Posts: 34
Hi Todd,

I tried your suggestion today and it worked like a charm

I am really happy that you went into such a detailed explanation. That's really helpful since I'm new at working with vbs and scripting in general.
I really appreciate the effort you guys are making to help your customers - thanks a lot.
Reply With Quote
  #11  
Old 05-06-2015, 10:20 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
You are welcome e2script. I am glad we could help. Thanks for the feedback.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply

Tags
mac , modify , script , search

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 02:02 PM.