PythonからCisco機器にTelnet接続してみました ~その1~
Cisco Aironet に MACアドレスを登録する処理を半自動化してみたく、Pythonを使ってみました。
まずは Python で Telnet接続し、簡単なCiscoコマンドを発行してみます。
実装環境
Pythonのバージョンは 3.6.1を使用
Ciscoのプロンプトは通常下記。
User Access Verification Password:
import getpass import telnetlib HOST = '192.168.xxx.xxx' password = getpass.getpass() tn = telnetlib.Telnet(HOST) if password: tn.read_until(b'Password: ') tn.write(password.encode('ascii') + b'\n') # Ciscoコマンド発行 tn.write(b'show clock' + b'\n') tn.write(b'exit' + b'\n') # read_until以降のテキストを出力 print(tn.read_all().decode('ascii'))
実行結果は以下の通り。
Password: <手入力> router>show clock Load for five secs: 0%/0%; one minute: 0%; five minutes: 0% Time source is SNTP, 18:55:19.232 JST Tue Jun 27 2017 18:55:19.232 JST Tue Jun 27 2017 router>exit
CodeIgniterのhelperを使ってCSSやJSなどのPATHを生成する
環境:
CSSとJSのディレクトリはCodeigniterのルートディレクトリに配置しています。
codeigniter_root/
|
|-application/
|
|-css/
|
|-js/
|
|-system/
|
コントローラ側の記述例
application/controller/Hoge.php
<?php class Hoge extends CI_Controller { public function __construct() { parent::__construct(); } function index(){ //helperでURL PATHを取得する $this->load->helper('url'); $this->load->view('hoge_view'); } } ?>
Codeigniterのindex.php
Codeigniterの初期状態は、URLに「index.php」を含む設定になっています。
環境:Codeigniter-3.1.4
URL例)
example.com/index.php/news/article/my_article
[参考]Codeigniter公式
CodeIgniter の URL — CodeIgniter 3.2.0-dev ドキュメント
index.phpと同じ階層に.htaccessを設置し、除外ルールを記述することでURLから「index.php」を省略してアクセスすることができます。
URLから「index.php」を取り除きたい場合は以下の通りです。
Apacheの設定
.htaccessの読み込みが有効になっていることを確認
AllowOverride 「None」の場合は「All」に変更してApacheを再起動する
# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All
.htaccessの編集
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [L]
config.phpの編集
application/config/config.phpの[index_page]を''に変更
/* |-------------------------------------------------------------------------- | Index File |-------------------------------------------------------------------------- | | Typically this will be your index.php file, unless you've renamed it to | something else. If you are using mod_rewrite to remove the page set this | variable so that it is blank. | */ $config['index_page'] = '';
atomが起動しなくなったときの備忘【Win】
起動エラーの場合は、何らかしらのパッケージが邪魔・悪さをしている可能性が高いようです。
1.atomをセーフモードで起動してみる
コマンドプロンプトで実行
atom --safe
※セーフモードは「パッケージを一切読み込まない」モード
2.全パッケージを最新化してみる
apm update
例)
C:\>apm update Package Updates Available (1) └── japanese-menu 1.12.0 -> 1.13.0 Would you like to install these updates? (yes) yes Installing japanese-menu@1.13.0 to C:\Users\xxxxx\.atom\packages done
これで起動しなければ、最近追加したパッケージを疑う
3.apm listでパッケージを一覧化して不要パッケージを削除する
apm uninstall パッケージ名
【追記】
4.SquirrelSetup.logを確認