Author Topic: storing integers  (Read 1586 times)

0 Members and 1 Guest are viewing this topic.

nosehook

  • Jr. Member
  • **
  • Posts: 8
  • Karma: 0
    • View Profile
storing integers
« on: August 24, 2015, 04:44:34 PM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: storing integers
« Reply #1 on: August 24, 2015, 05:56:38 PM »
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.

Code: [Select]
<?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!
« Last Edit: August 24, 2015, 07:09:38 PM by jitterjames »

nosehook

  • Jr. Member
  • **
  • Posts: 8
  • Karma: 0
    • View Profile
Re: storing integers
« Reply #2 on: August 25, 2015, 03:51:01 AM »
Thanks gentlemen! That really helped

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

Code: [Select]
<?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...