2013年1月31日木曜日

Plink.exe で一括ルータ設定!



plink.exe は putty のコマンドラインツールといったところでしょうか。

コマンドラインでssh接続したりできるexeファイルです。

Puttyのダウンロードページからダウンロードできます。

ページに You can download PuTTY here. という箇所があって here にリンクがはってあるので、そこをクリック。

すると一覧ページになるので、そこで plink.exe をダウンロードします。

無線APへMACフィルタを適用するのに、このツールを使って一括設定できるように目論みました。

plink.exe のヘルプを参照すると、以下のオプションがあります。


C:\test>plink
PuTTY Link: command-line connection utility Release 0.62
Usage: plink [options] [user@]host [command]
       ("host" can also be a PuTTY saved session name)

Options:

  -V        print version information and exit
  -pgpfp    print PGP key fingerprints and exit
  -v        show verbose messages
  -load sessname  Load settings from saved session
  -ssh -telnet -rlogin -raw -serial
            force use of a particular protocol
  -P port   connect to specified port
  -l user   connect with specified username
  -batch    disable all interactive prompts
The following options only apply to SSH connections:
  -pw passw login with specified password
  -D [listen-IP:]listen-port
            Dynamic SOCKS-based port forwarding
  -L [listen-IP:]listen-port:host:port
            Forward local port to remote address
  -R [listen-IP:]listen-port:host:port
            Forward remote port to local address
  -X -x     enable / disable X11 forwarding
  -A -a     enable / disable agent forwarding
  -t -T     enable / disable pty allocation
  -1 -2     force use of particular protocol version
  -4 -6     force use of IPv4 or IPv6
  -C        enable compression
  -i key    private key file for authentication
  -noagent  disable use of Pageant
  -agent    enable use of Pageant
  -m file   read remote command(s) from file
  -s        remote command is an SSH subsystem (SSH-2 only)
  -N        don't start a shell/command (SSH-2 only)
  -nc host:port
            open tunnel in place of session (SSH-2 only)
  -sercfg configuration-string (e.g. 19200,8,n,1,X)
            Specify the serial configuration (serial only)

C:\test>


どうやら、 -m ファイルを読み込むとファイルに記載したコマンドを実行してくれるようです。


ネットを探すと、こことかこことか参考になるサイトがありました。

ちなみに、Ciscoルータへ接続するときにユーザID、パスワードを入れてから、enable コマンドで特権モードへ入りますよね?

ユーザログイン時に、特権モードでログインしてくれるようにコンフィグする方法があるのです。

さっきの参考サイトをみてコンフィグしました。

-------------------------------------------------------------------
!
Router(config)#username root privilege 15 secret password
!
!
Router(config)#aaa new-model
!
!
Router1(config)#aaa authentication login default local
!
!
Router(config)#aaa authorization exec default local
!
-------------------------------------------------------------------

これで、ログインしたら特権モードになっているので、すぐにコマンド実行できます。

早速実行するコマンドをファイルにして、plink.exeに読み込ませます。以下、実行しました。

途中、キーをキャッシュするか聞かれますが、テストなので n にしています。

以下、実行結果
-----------------------------------------------------------------------------------------

C:\test\plink.exe -ssh -l root -pw password 192.168.1.100 -m C:\test\Command_file.txt

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 768 e3:b1:21:b1:aa:71:12:a1:1c:aa:ba:ea:1a:aa:a7:9d
If you trust this host, enter "y" to add the key to PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the connection.
Store key in cache? (y/n) n

Line has invalid autocommand "enable
password
conf t
no access-list 711
access-list 711 permit 0000.0000.0000   0000.0000.0000
access-list 711 permit 1111.1111.1111   0000.0000.0000
access-list 711 permit 2222.2222.2222   0000.0000.0000
access-list 711 permit 3333.3333.3333   0000.0000.00"
C:\>

-----------------------------------------------------------------------------------------


なんと、ダブルクォーテーションがあるのでコマンド入力時にエラーになっています!!

なぜにダブルクォーテーションが!!!

enable の前に " があるのがわかります?最後にもあるのですが。

色々テストしてみると、コマンドを1行だけにしてplimk.exeにファイルをよませると、ちゃんと実行できます。
が、複数行になると、アウトです。ダブルクォーテーションがあるのでNG!となってしまいます。。。。

参考サイトではうまくいっているみたいなのになー!!

その後、よくよく plink.exe のサイトを確認してみると、Routerで動作しないケースもあるって記載あったのであきらめてみました。

また今後調べるかもですが。。。









このエントリーをはてなブックマークに追加