星期日, 2月 20, 2011

利用DNS query查詢Wikipedia

頗有趣的東西,只要查詢xxx.wp.dg.cx的txt record就可以了!

如下指令
bin cacaegg$ dig txt unix.wp.dg.cx
; <<>> DiG 9.6.0-APPLE-P2 <<>> txt unix.wp.dg.cx
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 131 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 0 ;; QUESTION SECTION: ;unix.wp.dg.cx. IN TXT ;; ANSWER SECTION: unix.wp.dg.cx. 86400 IN TXT "Unix (officially trademarked as UNIX, sometimes also written as Unix with small caps) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe O" "ssanna. Today's Unix systems are split into various branches, developed over time by AT&T as well as various commercial... http://a.vu/w:Unix" ;; AUTHORITY SECTION: wp.dg.cx. 3600 IN NS ns.na.l.dg.cx. wp.dg.cx. 3600 IN NS ns.eu.l.dg.cx. ;; Query time: 942 msec ;; SERVER: 192.168.11.1#53(192.168.11.1) ;; WHEN: Sun Feb 20 14:12:53 2011 ;; MSG SIZE rcvd: 483


嫌太多資訊嗎? 加上個short吧。
bin cacaegg$ dig +short txt unix.wp.dg.cx
"Unix (officially trademarked as UNIX, sometimes also written as Unix with small caps) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe O" "ssanna. Today's Unix systems are split into various branches, developed over time by AT&T as well as various commercial... http://a.vu/w:Unix"

星期二, 2月 15, 2011

兩種在Linux下拿到亂數的方法

1. 寫個函數,從entropy拿。
linux kernel中有個entropy pool,這pool是由許多環境上的隨機因子造成的,
如Keyboard輸入的時間,滑鼠移動到的位置,disk存取的時間等等。
函式如下
unsigned long get_random(void){
unsigned long seed;
int fd;

fd = open("/dev/urandom", O_RDONLY);
if(fd == -1){
perror("open");
return 0;
}
if(read(fd, &seed, sizeof(seed)) < 0){ perror("read"); return 0; } if(close(fd)) perror("close"); return seed; }


2.另外一種方法,直接使用dd
$dd if=/dev/urandom of=/tmp/rand bs=1b count1
簡單又快速

星期四, 2月 10, 2011

Vim 尋找並取代

在命令模式下輸入

:%s/pattern/replacemet/g

就會取代所有的

要注意的是如果要group的話,
要加上escape的符號才行,如下:
\( \)
然後在replacement裡面
\0 代表match的pattern
\1 group1
依此類推


數量限制特別一點,只要加前頭就好:
\{n,m}