PR
キーワードサーチ
サイド自由欄
コメント新着
カテゴリ
* 複数の接続を一気に行うマクロ
* https://w.atwiki.jp/keiplus/pages/81.html
* MultiAutoLogin.js
* Poderosa マクロ で複数サーバーへドンドン接続しちゃう!方法 https://blog.gti.jp/post-159/
*/
import Poderosa;
import Poderosa.ConnectionParam;
import Poderosa.Terminal;
import Poderosa.Macro;
import Poderosa.View;
import System.Drawing;
import System.Threading;
var env = new Environment();
var ENCODE_TYPE = EncodingType.UTF8;
var NEWLINE_CHAR = NewLine.LF;
var SSH_PORT = 22;
var hostList = new Array();
var hostip = "192.168.0.1";
var loginuser = "USER";
var loginpw = "PASSWORD";
var loginport = "22";
//
// サーバー設定
//
hostList[0] = new Array();
hostList[0]['host'] = "hoostname"; // ドメイン OR IP
hostList[0]['id'] = "root"; // ログインアカウント
hostList[0]['pwd'] = ""; // ログインパスワード
hostList[0]['authtype'] = 1; // 認証タイプ 0: パスワード 1: SSH キーファイル
hostList[0]['key'] = "シークレットキーファイル名"; // 秘密鍵ファイル
hostList[0]['title'] = "サブタイトル"; // タブのタイトル
hostList[0]['port'] = 22; // SSHのポートを変更している場合は設定する
hostList[0]['encode'] = EncodingType.UTF8; // エンコードがデフォルト値以外の場合設定する
hostList[0]['newline_char'] = NewLine.LF; // 改行コードがデフォルト値以外の場合設定する
//hostList[0]['commands'] = new Array(); // コマンド発行の場合必要(任意)
//hostList[0]['commands'][0] = "pwd"; // コマンド1(任意)
//hostList[0]['commands'][1] = "ls -lat"; // コマンド2(任意)
hostList[1] = new Array();
hostList[1]['host'] = "hostname"; // ドメイン OR IP
hostList[1]['id'] = "root"; // ログインアカウント
hostList[1]['pwd'] = ""; // ログインパスワード
hostList[1]['authtype'] = 1; // 認証タイプ 0: パスワード 1: SSH キーファイル
hostList[1]['key'] = "シークレットキーファイル名"; // 秘密鍵ファイル
hostList[1]['title'] = "サブタイトル"; // タブのタイトル
hostList[1]['port'] = 22; // SSHのポートを変更している場合は設定する
hostList[1]['encode'] = EncodingType.UTF8; // エンコードがデフォルト値以外の場合設定する
hostList[1]['newline_char'] = NewLine.LF; // 改行コードがデフォルト値以外の場合設定する
//hostList[1]['commands'] = new Array(); // コマンド発行の場合必要(任意)
//hostList[1]['commands'][0] = "pwd"; // コマンド1(任意)
//hostList[1]['commands'][1] = "ls -lat"; // コマンド2(任意)
hostList[2] = new Array();
hostList[2]['host'] = "hostname"; // ドメイン OR IP
hostList[2]['id'] = "root"; // ログインアカウント
hostList[2]['pwd'] = ""; // ログインパスワード
hostList[2]['authtype'] = 1; // 認証タイプ 0: パスワード 1: SSH キーファイル
hostList[2]['key'] = "シークレットキーファイル名"; // 秘密鍵ファイル
hostList[2]['title'] = "サブタイトル"; // タブのタイトル
hostList[2]['port'] = 22; // SSHのポートを変更している場合は設定する
hostList[2]['encode'] = EncodingType.UTF8; // エンコードがデフォルト値以外の場合設定する
hostList[2]['newline_char'] = NewLine.LF; // 改行コードがデフォルト値以外の場合設定する
//hostList[2]['commands'] = new Array(); // コマンド発行の場合必要(任意)
//hostList[2]['commands'][0] = "pwd"; // コマンド1(任意)
//hostList[2]['commands'][1] = "ls -lat"; // コマンド2(任意)
//
// ログイン処理
//
for (var i = 0; i < hostList.length; i++) {
var ssh_port_num = SSH_PORT;
if (hostList[i]['port'] != null && hostList[i]['port'] != SSH_PORT) {
ssh_port_num = hostList[i]['port'];
}
var encoding_type = ENCODE_TYPE;
if (hostList[i]['encode'] != null && hostList[i]['encode'] != ENCODE_TYPE) {
encoding_type = hostList[i]['encode'];
}
var newline_char = NEWLINE_CHAR;
if (hostList[i]['newline_char'] != null && hostList[i]['newline_char'] != NEWLINE_CHAR) {
newline_char = hostList[i]['newline_char'];
}
var conn = connect(hostList[i]['host'], ConnectionMethod.SSH2, ssh_port_num, encoding_type, newline_char, hostList[i]['authtype'], hostList[i]['id'], hostList[i]['pwd'], hostList[i]['key'], hostList[i]['title']);
if (hostList[i]['commands']) {
if (hostList[i]['commands'].length > 0) {
wait(conn, "$");
for (var j = 0; j < hostList[i]['commands'].length; j ++) {
sendln(hostList[i]['commands'][j], conn);
}
}
}
}
env.Util.MessageBox("処理終了しました!");
function connect(host, method, port, encoding, newline_char, authtype, id, password, prikey, title) {
var param = new SSHTerminalParam(method, host, id, password);
if ( authtype == 1 ){
param.AuthType = AuthType.PublicKey;
param.IdentityFile = prikey;
}
else {
param.AuthType = AuthType.Password;
}
param.Caption = title+"["+host+"]";
param.Port = port;
param.Encoding = encoding;
param.TransmitNL = newline_char;
var connection = env.Connections.Open(param);
return connection;
}
function sendln(s, connection) {
connection.TransmitLn(s);
}
function wait(connection, command) {
Thread.Sleep(10);
var res = connection.ReceiveData();
while(res.indexOf(command) == -1) {
Thread.Sleep(10);
res += connection.ReceiveData();
}
}
クレカの下4桁を検索するバッチファイル 2024.08.26 コメント(6)
awk を使ったデータフィルター処理 2020.10.03 コメント(14)
電子書籍 管理ソフト calibre で書き出し… 2020.02.29