LoginSignup
3

More than 5 years have passed since last update.

CiscoユーザのためのTclバイトコード作成と実行

Last updated at Posted at 2017-03-09

以下の記事では、Cisco装置上でTclスクリプト実行例を紹介しました。
Cisco IOS EEMを使ったTclスクリプトの実行

Tclスクリプトは便利でいいのですが、中身が丸見えであるため、場合によっては困る方もいるかと思います。そこで、主にはTclスクリプトのロジックを隠蔽するために、(Tclスクリプトをコンパイルした)バイトコードの実行もサポートされています。

手っ取り早くバイトコードを作成し、実行する方法を紹介します。OSはWindows10を想定します。
以下のサイトから、tclpro141.exeをダウンロードし、インストールします。クリック、クリックでOKです。

http://tcl.tk/ftp/tclpro/download/tclpro141.exe
via http://tcl.tk/software/tclpro/eval/1.4.html

SS 2017-03-09 10.13.43.png

SS 2017-03-09 10.13.59.png

スクリーンショットでは、YESを選択していますが、ここではNOを選択します。(ライセンスは後で有効にします)
SS 2017-03-09 10.14.52.png

色々とインストールされていますが、binの中にあるprocomp.exeを使います。その前に、先ほどスキップしたライセンスを有効化する必要があります。
SS 2017-03-09 10.40.22.png

※ライセンス有効化をせず実行すると、License Managerで有効化してね、と促されます。

C:\Program Files (x86)\TclPro1.4\win32-ix86\bin>procomp.exe C:\Users\kazum\Desktop\a.tcl
TclPro Compiler -- Version 1.4.1
Copyright (C) Ajuba Solutions 1998-2017. All rights reserved.

Welcome to TclPro Compiler, and thank you for using TclPro 1.4.1.
Your license key or the name of a Ajuba Solutions License Server must
be entered to continue.  Please start TclPro License Manager, enter
the appropriate information when prompted, and then restart TclPro
Compiler.

スタートメニューから、TclPro License Managerを実行します。
SS 2017-03-09 10.41.28.png

ここでライセンスキーが必要になるのですが、Ajuba Solutionsは既に存在しておらず、サイトもないのですが、ライセンスキーはフリーで配布されており、こちらが利用できます。

http://wiki.tcl.tk/365

TclPro (Tcl/Tk) Key
1.2 8.0.5 1K14-2207-0H34-1U24-R8ZJ
1.3 8.2.0 1V45-2209-1G37-1U35-R8Y6
1.4.1 8.3.2 1094-320C-1G38-2U24-P8YY

こちらのキーと、適当なユーザ名を入力します。

SS 2017-03-09 10.59.57.png

これでprocomp.exeが利用できるようになりました。以下のように実行すると、デスクトップ上にtest.tbcが生成されました。

C:\Program Files (x86)\TclPro1.4\win32-ix86\bin>procomp.exe C:\Users\kazum\Desktop\test.tcl
TclPro Compiler -- Version 1.4.1
Copyright (C) Ajuba Solutions 1998-2017. All rights reserved.
This product is registered to: kikuta

あとは、Cisco IOS EEMを使ったTclスクリプトの実行を参考に、ルータに転送し、実行します。ちなみに中身は以下のように見えなくなっていることがわかります。

IOS
C4331-02#show bootflash: | i .tbc
 31        611 Mar 09 2017 01:48:39 +00:00 /bootflash/test.tbc
C4331-02#
C4331-02#more bootflash:test.tbc
# TclPro::Compiler::Include

if {[catch {package require tbcload 1.3} err] == 1} {
    error "The TclPro ByteCode Loader is not available or does not support the correct version"
}
tbcload::bceval {
TclPro ByteCode 1 0 1.3 8.3
5 0 39 10 0 0 20 0 3 5 5 -1 -1
39
)Nr<!'3E<!-l4pv)9E<!)QA9v.EW<!.Qr<!4`8s!4;tl#)'!!
5
8bgm#*!
5
Angm#'!
<snip>

Tclファイルと同じ方法で登録し、実行します。

IOS
C4331-02#show run | sec event manager
event manager directory user policy "bootflash:/"
event manager policy test.tbc type user
IOS
C4331-02#event manager run test.tbc
Hello Tcl!

C4331-02#
Mar  9 03:27:44.710: %HA_EM-6-LOG: test.tbc: Hello Tcl from Syslog!
C4331-02#

実行できました。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3