|
MSN 通常是用?斫徽劦, Liunx 下最有名的 MSN Client 當屬 gaim,
不過因為它是 GUI 的環境,要以 shell ?響脤?在不容易
(如果你能用 shell 控制 mouse 點在那裏就可以做到,但你能嗎 ? ()
1. 安裝 tmsnc (http://tmsnc.sourceforge.net/download.html)
我的例子是用 0.1.1 版本,你可以找別的版本自己開發,或參考我的例子也可以
代码:
- $>wget [url]http://unc.dl.sourceforge.net/sourceforge/tmsnc/tmsnc-0.1.1.tar.gz[/url]
- $>tar -zxvf tmsnc-0.1.1.tar.gz
- $>cd tmsnc-0.1.1
- # 看一下 Makefile , 裏面的 openssl 路?绞欠穹夏愕沫h境
- $>make
- $>make install
- $>tmsnc (啟動的樣子)
- .........
- .'------.' |
- | .-----. | |
- | |TMSNC| | |;.
- |*`-----'.|.' `;
- `---------' .;'
- .''''////////;'
- / ######### /;/ The
- / ######### // textbased
- `-----------' alternative!
复制代码
Login: abel@twnic.net.tw
Your login-address is abel@twnic.net.tw
Enter password:
2.TMSNC 的指令說明
代码:
# tmsnc 的 command 說明 (Readme),如果你要完善你的功能,就要詳讀任何的說明
Availible commands in TMSNC are:
* help show a list of availible commands
* clear clear the screen
* nick <name> set your nickname to <name>
* status <string> where <string> is online, busy, brb,
* away, phone, lunch or hidden
* quit logout from server and quit TMSNC
* add <address> add <address> to the contact-list
* block <address> prevent <address> from obtaining your status
* unblock <address> reverse the block
* remove <address> remove <address> from contact-list
* window <n> or TAB change current window to <n>
* window close or F7 close current window and conversation
* chat <address> or Enter start a new conversation with <address>
由以上我們可以知道, tmsnc 我們巳經裝好了,所以就可以?碜 shell 發送 msn 的工作了!
用 shell ?戆l,最好的工具是 expect , 這個工具的說明,你可以在 man page 中找到詳細
解說
3.
3.1
範例一(簡單版):
代码:
- #!/usr/bin/expect
- # filename=send.exp
- log_file ./exp.log
- spawn tmsnc -l 你申請的MSN帳號
- expect "Enter password:"
- send "你的密碼\r"
- expect -re ".* can't control me*"
- sleep 5
- send "/chat [lindex $argv 0]\n"
- expect -re ".*!.*"
- sleep 1
- send "Now: [exec date]\n"
- sleep 1
- send "[lindex $argv 1]\n"
- sleep 3
- send "/window close\r"
- send "/quit\r"
复制代码
用法:
代码:
#請注意, MSN?息需為 UTF-8 encoding
$>./send.exp MSN連絡人 MSN?息
3.1
範例二(稍複雜版):
代码:
- #!/usr/bin/expect
- # log file , for debug
- log_file ./exp.log
- #設定?息路經
- set workdir "/www/htdocs/html/msn/msg"
- # -l 指定 MSN contact, 你可以 tmsnc -h ?砹私鈪
- spawn tmsnc -l 你申請的MSN帳號
- sleep 1
- # 出現 password 時,送出密碼
- expect "Enter password:"
- send "你的密碼\r"
- sleep 1
- # 出現 control me 時,表示 tmsnc 載入完成
- expect -re ".* can't control me*"
- sleep 3
- # 無限迴圈,讀取?息檔
- while {1} {
- sleep 1
- #取得 ?息檔中第一行,我個人的定義是 MSN addr
- set msn_addr [ exec cat $workdir/msg.utf8 | head -1 ]
- #如果?]有第一行,則回到 loop
- if {$msn_addr!=""} {
- #對誰發送說明,指令請看 Readme
- send "/chat $msn_addr\n"
- sleep 1
- #出現對話視窗後
- expect -re ".*!.*"
- #發送現在時間
- send "Now: [exec date ]\n"
- sleep 1
- #發送該檔案的第二行起的?息,請注意,?息需為 UTF-8 的 encoding ,您可使用 iconv ?磙D換
- send "[exec cat $workdir/msg.utf8 | sed -e 1d ] \n"
- sleep 1
- #關?]對話
- send "/window close\n"
- sleep 1
- #清除?息檔
- set cmd [exec echo -n "" > $workdir/msg.utf8]
- }
- }
- send "/quit\r"
复制代码
現在,我們可以?韺懸粋網頁程式,?碜錾侠械 msg.utf8 的處理
代码:
[PHP]
<?php
while ( list($key,$val)=each($_GET))
$$key=$val;
if (isset($smt1)) {
$msn=iconv("GB2312","UTF-8",$msg);
$fp=fopen("/www/htdocs/html/msn/msg/msg.utf8",'w');
fwrite($fp,"$txt1\n$msn");
fflush($fp);
fclose($fp);
system("cat ./msg/msg.utf8");
echo "<BR>\n";
}
?>
<html><body>您要加我才能送?息給你, 請新增 MSN 連絡人: abel@twnic.net.tw<BR>
測試完後再把我刪了即可, 非常感謝!<BR>
<form method=GET>
我要傳送給 msn:<input type=text value="<?php echo $txt1;?>" name=txt1>
<input type=text name=msg value="<?php echo $msg;?>" maxlength=255>?息
<input type=submit value=send name=smt1>
</form> </body></html>
[/PHP]
嗯... Good, 如此,你就可以用
代码:
- $>wget [url]http://你的url/msn.php?smt1=send&txt1=MSN連絡人&msg=MSN?息[/url]
复制代码
?戆l放?息了,?際的例子,您可參考
http://211.72.210.251/msn/msn.php
5.
?用範例(mrtg)
代码:
- WorkDir: /www/htdocs/html/mrtg
- Refresh: 300
- Interval: 5
- Language: Big5
- Options[_]: growright, noinfo, gauge
- #LogFormat: rrdtool
- #PathAdd: /usr/bin/
- #LibAdd: /usr/lib/perl/
- #-----------------------Target Begin------------------------------------
- Target[localhost-mysql]:`check_mysqlsh localhost `
- MaxBytes1[localhost-mysql]:200
- MaxBytes2[localhost-mysql]: 100
- Title[localhost-mysql]: 211.72.210.251 MYSQL Threads/Qps Stat
- Legend1[localhost-mysql]: 行程數
- Legend2[localhost-mysql]: 秒查詢量
- LegendI[localhost-mysql]: Threads
- LegendO[localhost-mysql]: Qps
- YLegend[localhost-mysql]: Threads/Qps
- PageTop[localhost-mysql]: <h1>211.72.210.251 MYSQL Threads/Qps Stat</h1>
- ThreshMaxI[procmail-mysql]: 30
- ThreshMinI[procmail-mysql]: 1
- ThreshMaxO[procmail-mysql]: 50
- ThreshProgI[procmail-mysql]:/www/htdocs/html/mrtg/alert/mysql_alert.sh
- ThreshProgO[procmail-mysql]:/www/htdocs/html/mrtg/alert/mysql_alert.sh
复制代码
以上的例子是我在監控 mysql 的行程式及查詢量,若行程數超過 30 個,或<=1 個時,或是mysql 每秒
查詢超過 50 個 query, 啟動 mysql_alrtt.sh 程式,而 mysql_alert.sh 程式如下
代码:
- #!/bin/sh
- # mrtg 會傳送三個參數給 ProgI/ProgO , 以利 alert 程式處理
- # 分於為 Target name/所設定的警告值/現在的值
- target=$1
- alert_val=$2
- curr_val=$3
- wget "http://211.72.210.251/msn/msn.php?smt1=&txt1=MSN連絡人&msg=MRTG 所監測的\
- $target,發生問?},您所設的現在值 $curr_val 超過您所設的 $alert_val\
- \n請您參考 http://你的網頁/$target.html" -O /tmp/msn.log
复制代码
4. 結語
我個人目前系統的 Alert 都是透過 MSN ?碜黾磿r發放的,你可以寫一個檢查系統的程式, check 到有
alert 狀況時,就可以用 wget .... ?硭统鲇?息給很多相關人員,只要您想送什麼,就可以送什麼,透過
shell 放送,更增您的方便性(當然,也可以送病毒)
註:如果您充份了解 expect 的字串處理,可以反過?,讓 tmsnc + expect 幫您做事哦, 例如和他交談
"exec ls -la /tmp" , 這個 exec 是 prefix, 你只要能拆解出 "ls -la /tmp", 就可以在 msn 中看
到 /tmp 下的檔案列表了 ! 這絕對是真的, 就看你的能力囉
(以上所出現的 email 或 msn address 皆是假的,不要寄信?,不然你會被列入 RBL)
原文请看这里:http://bbs.chinaunix.net/forum/viewtopic.php?t=575520 |
|