同樣因某需求,我們希望tcpdump 一天出一次檔就好了,以方便判讀。
語法是:
tcpdump -G 10 -i eth1 -w /tmp/test-%F-%T.cap
要符合我們的需求的話,可能就是
tcpdump -G 86400 -i eth1 -w /tmp/NTU-%F.cap
P.S. 60*60*24 = 86400,執行時間:23:59:59
補充一下。
如果要看packet的內容的話 (封包可能被切斷,而無法用tcpdump或其它指令,例如ngrep或tcpflow看其內容。)
可以用tshark -V的指令來處理。
man裡面的解釋是這樣:
-V Cause TShark to print a view of the packet details rather than a one-line summary
of the packet.
可以看packet detail而不是看一行的summary。
2013年3月12日 星期二
2013年3月10日 星期日
php將unicode編碼轉為utf-8的方法
有時候會遇到這種狀況:
"\u9060\u50b3\u96fb\u4fe1",這個是典型的unicode編碼。
但是這畢竟不是給人看的。
所以我們需要把它轉換為utf-8或其它編碼。
網路上有人已經寫好了,那我們就直接拿來用囉。
"\u9060\u50b3\u96fb\u4fe1",這個是典型的unicode編碼。
但是這畢竟不是給人看的。
所以我們需要把它轉換為utf-8或其它編碼。
網路上有人已經寫好了,那我們就直接拿來用囉。
$str = "\u9060\u50b3\u96fb\u4fe1";
echo unicode2utf8($str);
function unicode2utf8($str){
if(!$str) return $str;
$decode = json_decode($str);
if($decode) return $decode;
$str = '["' . $str . '"]';
$decode = json_decode($str);
if(count($decode) == 1){
return $decode[0];
}
return $str;
}
來源是:http://www.welefen.com/php-unicode-to-utf8.html
2013年3月6日 星期三
2013年3月5日 星期二
windump 列出網卡的方法
某需求用到,記錄一下。
windump -D 列出所有網卡的NPF name
然後就可以存檔了:
windump -i xxxxxx -w windump.pcap -s 2048
-s 2048指的是capture lenght,設定為2048是為了某廠牌設備讀取方便。
丟給linux讀一下:
file windump.pcap
這樣就會是我們需要的lenght 2048的檔案了。不加-s 2048預設值是96。 (*wireshark的預設值是65535...)
windump.pcap: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 2048)
windump -D 列出所有網卡的NPF name
然後就可以存檔了:
windump -i xxxxxx -w windump.pcap -s 2048
-s 2048指的是capture lenght,設定為2048是為了某廠牌設備讀取方便。
丟給linux讀一下:
file windump.pcap
這樣就會是我們需要的lenght 2048的檔案了。不加-s 2048預設值是96。 (*wireshark的預設值是65535...)
windump.pcap: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 2048)
2013年3月1日 星期五
2013年2月28日 星期四
在cron呼叫shell script時若有使用grep需注意時間格式
花了半天的時間,結果和一大早猜測的結果相同 ><,白白花了三個小時的時間....
在cron呼叫shell script時若有使用grep需注意時間格式
在shell裡的輸出:
-rwxr-xr-x 1 root root 57 2013-03-01 14:29 cp_NTU.sh
-rw-r--r-- 1 root root 6593 2013-03-01 10:50 getdata.php
-rwxr-xr-x 1 root root 507 2013-03-01 14:28 get_yesterday.sh
-rwxr-xr-x 1 root root 155 2013-03-01 10:47 output.sh
在crontab裡呼叫時的輸出:
-rw-r--r-- 1 root root 6377 Mar 21 2012 08-circuit
-rw-r--r-- 1 root root 7647 Apr 10 2012 1
-rw-r--r-- 1 root root 27103 Mar 17 2012 11-3.cfg
-rw-r--r-- 1 root root 9873 Mar 17 2012 11-3.csv
-rw-r--r-- 1 root root 1419670 Mar 19 2012 139.175.235.83.txt
所以如果在cron呼叫shell script時若有使用grep需注意時間格式
例如:
/bin/ls -l --time-style="+%Y-%m-%d %H:%M:%S" /mnt/windump/NTU_old/NTU* | /bin/grep $yesterday | /bin/awk'{print "/bin/cp -p " $8 " /home/klting/NTU"}' > /home/klting/NTU/cp_NTU.sh
在ls -l的後面,要使用time-style,強制指定格式。
在cron呼叫shell script時若有使用grep需注意時間格式
在shell裡的輸出:
-rwxr-xr-x 1 root root 57 2013-03-01 14:29 cp_NTU.sh
-rw-r--r-- 1 root root 6593 2013-03-01 10:50 getdata.php
-rwxr-xr-x 1 root root 507 2013-03-01 14:28 get_yesterday.sh
-rwxr-xr-x 1 root root 155 2013-03-01 10:47 output.sh
在crontab裡呼叫時的輸出:
-rw-r--r-- 1 root root 6377 Mar 21 2012 08-circuit
-rw-r--r-- 1 root root 7647 Apr 10 2012 1
-rw-r--r-- 1 root root 27103 Mar 17 2012 11-3.cfg
-rw-r--r-- 1 root root 9873 Mar 17 2012 11-3.csv
-rw-r--r-- 1 root root 1419670 Mar 19 2012 139.175.235.83.txt
所以如果在cron呼叫shell script時若有使用grep需注意時間格式
例如:
/bin/ls -l --time-style="+%Y-%m-%d %H:%M:%S" /mnt/windump/NTU_old/NTU* | /bin/grep $yesterday | /bin/awk'{print "/bin/cp -p " $8 " /home/klting/NTU"}' > /home/klting/NTU/cp_NTU.sh
在ls -l的後面,要使用time-style,強制指定格式。
訂閱:
文章 (Atom)