2011年4月17日 星期日

2011年4月15日 星期五

如何測試你的平台是big endian 或 little endian

* little endian versus big endian */ 

 /*
  * add: z z+1 z+2 z+3
  * mem: 0D 0C 0B 0A //big endian
  * mem: 0A 0B 0C 0D //little endian
  * V = 0x0D0C0B0A
  */
 

 #include <stdio.h> 
 #include <stdlib.h> 
 int  main( void ) 
 { 
     int  V = 0x0D0C0B0A; 
     char  c = *( char  *)(&V)
     
     if  (c == 0x0A || c == 0x0D) { 
         if  (c == 0x0A) 
             printf( "little endian machine" )
         else 
             printf( "big endian machine" )
     } else 
         printf( "test error" )
     putchar( '\n' )
     exit(0)
}   

2011年4月1日 星期五

shellinabox - 在瀏覽器操作 Linux Shell


環境: Fedora 13, Shell In A Box v2.10 (revision 225)

安裝 shellinabox
#安裝必要套件
sudo yum install subversion gcc make automake pam-devel openssl-devel openssh-clients
#安裝 Shell In A Box
svn checkout http://shellinabox.googlecode.com/svn/trunk/ shellinabox
cd shellinabox
./configure
make
sudo make install

#若 SELinux 為 Enforcing, 需進行以下處理
sudo cp -Z system_u:object_r:etc_t:s0 etc-pam.d-shellinabox-example /etc/pam.d/
#查看 openssl 版本
rpm -q openssl
#若 openssl 版本高於 0.9.8
#則必須在 openssl 0.9.8 以下的電腦製作 ssl 憑證: certificate.pem
#再把 certificate.pem 檔案複製到 shellinabox 電腦的 /tmp 目錄下

openssl req -x509 -nodes -days 3650 -subj '/CN=localhost/' \
  -newkey rsa:1024 -keyout certificate.pem -out certificate.pem

註: openssl 1.0.0 所產生的 certificate.pem 會造成 ssl handshake failure
執行 shellinabox
#不使用 SSL, 預設聆聽 tcp 4200 port
$ shellinaboxd --disable-ssl
#使用 SSL, 聆聽 tcp 1234 port
$ shellinaboxd --cert /tmp --port 1234
#使用 SSL, 聆聽 tcp 1234 port, 黑底白字
$ shellinaboxd --cert /tmp --port 1234 --css /usr/local/share/doc/shellinabox/white-on-black.css
#使用 SSL, 聆聽 tcp 1234 port, 背景執行
$ shellinaboxd --background --cert /tmp --port 1234
#在 SELinux=Enforcing 環境下以 root 執行
# shellinaboxd --background --cert /tmp --service /:SSH
以 service 方式管理 shellinabox
su -
chmod 700 /usr/local/bin/shellinaboxd
vi /etc/init.d/shellinabox

#!/bin/sh
### BEGIN INIT INFO
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
 
case "$1" in
'start')
    /usr/local/bin/shellinaboxd --background --cert /tmp --service /:SSH
    ;;
'stop')
    pkill shellinaboxd
    ;;
esac
exit 0
chmod +x /etc/init.d/shellinabox
chkconfig --add shellinabox
service shellinabox start
參考資料:

LINK from:http://cha.homeip.net/blog/2010/09/2699.html

How to use simple speedtest in RaspberryPi CLI

  pi@ChunchaiRPI2:/tmp $  wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py --2023-06-26 10:4...