vncdotool - VNC bot

最後更新: 2019-06-25

HomePage

https://github.com/sibson/vncdotool/

目錄

  • Install
  • Basic Usage
  • Capture Screen
  • move & click
  • delay 與 pause
  • Macro

 


Install

 

# 建立 virtualenv

pip install virtualenv

virtualenv venv-vncdotool

source venv-vncdotool/bin/activate

# 在 virtualenv 安裝 vncdotool

pip install vncdotool

它依賴

  • Twisted
  • Pillow
  • pycryptodomex - a self-contained Python package of low-level cryptographic primitives
  • ...

Test & Check Version

vncdo --version

vncdo 1.2.0

 


Basic Usage

 

Connect VNC Server

-s SERVER              # Format ADDRESS[:DISPLAY|::PORT]

-p PASSWORD

i.e.

# Default port: 5900

vncdo -s 192.168.88.150 capture screen.png

# Cust port: 5921

vncdo -s 192.168.88.150:21 key enter

# Cust port: 15921

vncdo -s 192.168.88.150::15921 type "hello world"

一 cmd 多 action

move 500 100 click 1 type "ping 192.168.88.1" key enter

特別 key

enter, esc, shift-a, ctrl-c, ctrl-alt-del, super-r

 


Capture Screen

 

# capture full screen

vncdo -s $server::$port capture tmp.png

# capture a region of the screen

vncdo -s $server::$port rcapture FILE X Y W H

Example

compare_full_screen.sh

function compare_full_screen(){
while true
    do
        vncdo -s $server::$port capture tmp.png
        r=`compare -metric PSNR $1 tmp.png /dev/null 2>&1`
        i=${r%.*}
        echo $i
        if (( $i > 20 )); then
            echo "SAME"
            break
        fi
        sleep 5
    done
}

compare_full_screen myscreen.png

 


move & click

 

 * You should almost always issue a click with move

正確:

vncdo move 100 100 click 1

錯誤

vncdo move 100 100
vncdo click 1

 


delay 與 pause

 

--delay=MILLISECONDS  # delay MILLISECONDS between action [Default: 10ms]

i.e.

vncdo --delay=2000 -s $server::$port type c type m type d

pause SECONDS              #wait SECONDS before sending next command

vncdo -s $server::$port key super-r pause 2
vncdo -s $server::$port key delete

 


Macro

 

i.e. Disable firewall rule

#!/bin/bash

## vnc host setings
Server="192.168.88.150"
Port="5921"

VNCDO=/root/MyScripts/vnc_bot/venv-vncdotool/bin/vncdo
VNCDO_CON="$VNCDO -s $Server::$Port"

function DisFwGrp() {
        local fwGrpNm="$1"
        # start cmd.exe
        $VNCDO_CON key super-r type cmd key enter
        # cli to disable fw rule group
        $VNCDO_CON type "netsh advfirewall firewall set rule group=" \
        key shift-\" type "$fwGrpNm" key shift-\" \
        type " new enable=no" key enter
        # exit cmd.exe
        $VNCDO_CON type "exit" key enter
}

#DisFwGrp "Remote Desktop"

 * "double quotes" 要用     key shift-\"     發送

 


Changelog

 

1.2.0 (2023-06-06)
bugfix

1.1.0 (2023-04-01)
Support Python3

1.0.0 (2020-04-10)
add ZRLE encoding

0.13.0 (2019-11-21)
new flag –incremental-refreshes, increased compatibility of capture
exit non-zero and print to stderr for unknown commands

 

 

Creative Commons license icon Creative Commons license icon