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

2011年3月26日 星期六

STP (Spanning – Tree Protocol)

STP (Spanning – Tree Protocol) 主要的目的是為了避免Switch Loop 為Cisco設備專有的技術



* 初學者容易把 STP 和 VTP(vlan) 搞混,這兩個是不同的技術。



主要依靠:

1.BPDU(Bridge Protocol Data Unit)

2.Spanning Tree advertisement (STA)

來讓switch接受到neighbor switch的BPDU來進行資料的比對。



BPDU:(Priorty、MAC address、Port Cost、Port Priority、Port ID……等等的資訊)



運作流程:

1.首先會在Switch之中,依Priorty最小 或 MAC address最小 的Switch當做Root Bridge。

2.在Root Bridge上每一個Port都是Designed Port (被定義的Port)。

3.其它沒有被選為Root Bridge的Switch就稱為Non-Root Bridge。

4.在這些Non-Root Bridge上的Port,會選出一個到達Root Bridge的成本(Cost)最低的當作Root Port。

5.其它連接 Switch 之間的Non-Designed Port(未被定義的Port),就會被Block起來。


*被Block起來的Port,仍會聆聽BPDU,一但網路出了問題,就會馬上啟用(Forwarding),修復網路。



*Port Fast:使用在End-User的Port:(參考Cisco網站原文的技術書)

- 因為 Cisco 設備,都會對於插上Port的端點進行迴圈的偵測,大約 15秒 + 15秒,因為如果你的網路線

端點,是 Server 或是 PC host 的話,就可以設定該Port為PortFast,加快網路間的收斂(Converse)

- Port Fast Configuration:Switch(config-if)# spanning-tree portfast (2900系列)



本文的引用網址  http://blog.xuite.net/wizardyuy/pcblog/12731221/track

2011年3月25日 星期五

IPad,IPhone,IPod 使用一般電腦USB充電方法

一般電腦USB 因輸出電流過小(USB介面標準最大輸出電流量只有500mA),而無法對IPad,IPhone...等device進行充電。Apple為了加快充電 速度,進而設計出「快速」和「慢速」兩種充電模式。iPad電池容量大,被設定在需要約1A(1000mA)以上的電流量,才能進入慢速充電模式,因此有 許多電腦無法為它充電。至於iPhone、iPod Touch,單純連接電腦是屬於慢速充電模式,想進入快速充電模式,電流量則是必需達到0.7A(700mA)左右。

透過安裝下列軟體,可以使USB送出模擬偏壓訊號的方式,讓裝置以為是連接到變壓器,進而啟動充電模式。

ASUS Ai charger:  http://dlcdnet.asus.com/pub/ASUS/misc/utils/AiCharger_V10006_XpVistaWin7.zip

2011年3月8日 星期二

SNAT V.S MASQUERADE

SNAT改變包的源位址,這在極大程度上可以隱藏你的本地網路或者DMZ等。一個很好的例子是我們知道防火牆的外部位址,但必須用這個位址替換本地網路位 址。有了這個操作,防火牆就 能自動地對包做SNAT和De-SNAT(就是反向的SNAT),以使LAN能連接到Internet。
 
MASQUERADE的作用和SNAT完全一樣,只是電腦 的負荷稍微多一點。因為對每個匹配的包,MASQUERADE都要查找可用的IP地址,而不象SNAT用的IP位址是配置好的。當然,這也有好處,就是我 們可以使用通過PPP、 PPPOE、SLIP等撥號得到的地址,這些位址可是由ISP的DHCP隨機分配的。

How to overclock RB450G/RB750G from 600Mhz to 800Mhz

Login RouterOS terminal

then type :
                    /system routerboard settings set cpu-frequency=800

How to repair and clone disk with ddrescue

  ddrescue  is a tool that can be used to repair and clone disks on a  Linux system . This includes hard drives, partitions, DVD discs, flas...