News:

There is now a ChangeLog page on the wiki
New developments are added at the bottom of the page.

Main Menu

storing integers

Started by nosehook, August 24, 2015, 04:44:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nosehook

I assume I am not the first one, however I have run into a challenge I can not resolve.
In order to understand the program better, I am trying to make a network scanner.
What I want to do is to scan 192.168.0.{1}, where {1} is 100 to 200 (this part I am succesfull).
What I also want to do is to increase a counter every time I get a response via ping, but the problem I run into is that result.setvar seems to create a string (as does RegEx), is this correct? I am unsuccesful in retrieving the integer (whole number) from that string (I am new to Python) and do a +1 to it.
The idea is to store the first hit (IP-number) in IP{var.nr}, so that if I later recall IP{3} I get the IP-nr that was the 3rd hit
Is there a workaround?

Hope someone can point me in the right direction  :)

jitterjames

#1
This is not necessarily the best way to do it depending on the rest of your code but here is an example that illustrates the answer to your question.  The fact that VC is storing variables as a string is not really a problem in this case.  However it might make more sense to move everything into your python, especially if your network tests are taking a long time to execute and need to be put into their own thread.

<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.7-->
<command id="203" name="set var and increment" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>counter</param>
      <param>5</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecString</cmdType>
    <params>
      <param>result = {var.counter}+1</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>counter</param>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{Var.counter}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>


I should probably mention that the Python plugin can't directly modify any variable in VoxCommando except for {LastResult}

At least I don't think it can!

nosehook

Thanks gentlemen! That really helped

The code does what it needs to do now (changes/expansion pending) and looks like this:

<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.7-->
<commandGroup open="True" name="ip scan" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="1393" name="ip scan 1" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="1" loopMax="0" description="">
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>ip</param>
        <param>0</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.TriggerEvent</cmdType>
      <params>
        <param>ip scan 2</param>
        <param>{i}</param>
      </params>
      <cmdRepeat>7</cmdRepeat>
    </action>
  </command>
  <command id="1400" name="ip scan 2" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>result= {1} + 105</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>value</param>
        <param>{LastResult}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Launch.Capture</cmdType>
      <params>
        <param>C:\Windows\System32\ping.exe</param>
        <param> -n 1 -w 1000 192.168.0.{var.value}</param>
        <param>True</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>\s(\d+)\s\W0\W\sloss</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>LastActionSuccess</ifType>
      <ifParams>&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>PY.ExecString</cmdType>
          <params>
            <param>result = {var.ip}+1</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>Results.SetVar</cmdType>
          <params>
            <param>ip</param>
            <param>{LastResult}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>Results.SetVar</cmdType>
          <params>
            <param>online{var.ip}</param>
            <param>192.168.1.{var.value}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <params>
            <param>hit {var.ip} at address {var.online{var.ip}}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <event>ip scan 2</event>
  </command>
</commandGroup>


The range is now minimal for trail purposes only.
Thank you for the great support. I should probably start to study Python...