存档

‘转载’ 分类的存档

Using Serial Devices in FreeBSD / How to set a terminal baud rate

2010年8月24日 16hot 没有评论

http://www.clearchain.com/blog/posts/using-serial-devices-in-freebsd-how-to-set-a-terminal-baud-rate

Recently I was working on a php command line program that required access to a serial port.

Initially developed under Linux the program was then shifted to it’s permanent location on a FreeBSD server. This is where we first started having problems. Initially we discovered the server didn’t have a native serial port. We fixed this using a USB to serial converter/dongle (FTDI Chipset). This was fine as FreeBSD has the ufdti kernel module. Upon loading the module new devices appears in /dev

crw-rw----  1 uucp  dialer    0, 157 Oct  6 08:39 /dev/cuaU0
crw-rw----  1 uucp  dialer    0, 158 Oct  6 08:39 /dev/cuaU0.init
crw-rw----  1 uucp  dialer    0, 159 Oct  6 08:39 /dev/cuaU0.lock
crw-rw-rw-  1 root  wheel     0, 154 Jan  8 10:50 /dev/ttyU0
crw-------  1 root  wheel     0, 155 Oct  6 08:39 /dev/ttyU0.init
crw-------  1 root  wheel     0, 156 Oct  6 08:39 /dev/ttyU0.lock

We attempted to connect to our device using screen (screen /dev/ttyU0 115200) and everything worked as expected. We could send AT commands to the device all ok.
We then stopped screen and ran our php program. It ended up hanging on a fgets call to the serial port. This is really strange we though.
Next we queried the port to find out what baud rate it was set at:

>stty -f /dev/ttyu0
speed 9600 baud;
lflags: echoe echoke echoctl
oflags: tab0
cflags: cs8 -parenb

Strange we thought as we’d just connected with screen at 115200. Under linux we use screen to set the baud rate, all other programs accessing the port use the port at 115200. So what had set it back to 9600 baud?
We tried to use stty to set the speed:

>stty -f /dev/ttyU0 speed 115200
>stty -f /dev/ttyu0
speed 9600 baud;
lflags: echoe echoke echoctl
oflags: tab0
cflags: cs8 -parenb

What on earth was happening? We set the speed to 115200 but directly quering the port again indicated it was still at 9600 baud? At this point we were perplexed.
Eventually we found the solution. The newer FreeBSD terminal drivers provide the *.init devices, in this case /dev/ttyU0.init . These devices indicate the terminal settings to be applied to the terminal when the device is closed. Whilst Linux leaves the device in the same state the last program put the port into, FreeBSD restores the terminals state to what ever is specified in the init file. So a quick command:

> stty -f /dev/ttyU0.init -icanon -isig -echo echoe echok echoke echoctl -icrnl -ixany -imaxbel ignpar -opost -onlcr -oxtabs cs8 -parenb -hupcl clocal

And then to check:

> stty -f /dev/ttyU0
speed 115200 baud;
lflags: -icanon -isig -echo echoe echok echoke echoctl
iflags: -icrnl -ixany -imaxbel ignpar
oflags: -opost -onlcr -oxtabs
cflags: cs8 -parenb -hupcl clocal

Excellent. The terminal was now configured exactly how we wanted. We ran the program and it worked like a charm!

分类: BSD/linux, 转载 标签:

WP-Syntax语法

2010年8月8日 16hot 没有评论

Usage

Wrap code blocks with <pre lang="LANGUAGE" line="1"> and </pre> where LANGUAGE is a GeSHi supported language syntax. See below for a full list of supported languages. The line attribute is optional.

Example 1: PHP, no line numbers

<pre lang="php">
<div id="foo">
<?php
  function foo() {
    echo "Hello World!\\n";
  }
?>
</div>
</pre>

Example 2: Java, with line numbers

<pre lang="java" line="1">
public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}
</pre>

Example 3: Ruby, with line numbers starting at 18

<pre lang="ruby" line="18">
class Example
  def example(arg1)
    return "Hello: " + arg1.to_s
  end
end
</pre>

Example 4: If your code already has html entities escaped, use escaped="true" as an option

<pre lang="xml" escaped="true">
&lt;xml&gt;Hello&lt;/xml&gt;
</pre>

Supported Languages

The following languages are supported in the lang attribute:

abap, actionscript, actionscript3, ada, apache, applescript, apt_sources, asm, asp, autoit, avisynth, bash, bf, bibtex, blitzbasic, bnf, boo, c, c_mac, caddcl, cadlisp, cil, cfdg, cfm, cmake, cobol, cpp-qt, cpp, csharp, css, d, dcs, delphi, diff, div, dos, dot, eiffel, email, erlang, fo, fortran, freebasic, genero, gettext, glsl, gml, bnuplot, groovy, haskell, hq9plus, html4strict, idl, ini, inno, intercal, io, java, java5, javascript, kixtart, klonec, klonecpp, latex, lisp, locobasic, lolcode lotusformulas, lotusscript, lscript, lsl2, lua, m68k, make, matlab, mirc, modula3, mpasm, mxml, mysql, nsis, oberon2, objc, ocaml-brief, ocaml, oobas, oracle11, oracle8, pascal, per, pic16, pixelbender, perl, php-brief, php, plsql, povray, powershell, progress, prolog, properties, providex, python, qbasic, rails, rebol, reg, robots, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, tcl, teraterm, text, thinbasic, tsql, typoscript, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xml, xorg_conf, xpp, z80

(Bold languages just highlight the more popular ones.)

Styling Guidelines

WP-Syntax colors code using the default GeSHi colors. It also uses inline styling to make sure that code highlights still work in RSS feeds. It uses a default wp-syntax.css stylesheet for basic layout. To customize your styling, copy the default wp-content/plugins/wp-syntax/wp-syntax.css to your theme’s template directory and modify it. If a file named wp-syntax.css exists in your theme’s template directory, this stylesheet is used instead of the default. This allows theme authors to add their own customizations as they see fit.

Advanced Customization

WP-Syntax supports a wp_syntax_init_geshi action hook to customize GeSHi initialization settings. Blog owners can handle the hook in a hand-made plugin or somewhere else like this:

<?php
add_action('wp_syntax_init_geshi', 'my_custom_geshi_styles');

function my_custom_geshi_styles(&$geshi)
{
    $geshi->set_brackets_style('color: #000;');
    $geshi->set_keyword_group_style(1, 'color: #22f;');
}
?>

This allows for a great possibility of different customizations. Be sure to review the GeSHi Documentation.



分类: 转载 标签:

今天你孝了没有(转)

2010年7月21日 16hot 没有评论

在整理文件夹的时候,看到这篇以前拷贝的文章,看了后还是很受教育。特此贴出来和大家分享。

——————————————————————————————————————————

媳妇说:“煮淡一点你就嫌没有味道,现在煮咸 一点你却说咽不下。你究竟怎想怎么
样?”

母亲一见儿子回来,二话不说便把饭菜往嘴里送。她怒瞪他一眼。他试了一口,马上吐
出来, 儿子说:“我不是说过了吗,妈有病不能吃太咸!” “那好!妈是你的,以后
由你来煮!”媳妇怒气冲冲地回房。儿子无奈地轻叹一声,然后对母亲说:“妈,别吃
了,我去煮个面给?”

“仔,你是不是有话想跟妈说,是就说好了,别憋在心里!”

“妈,公司下个月升我职,我会很忙,至于老婆,她说很想出来工作,所以……”

母亲马上意识到儿子的意思:“仔,不要送妈去老人院。”声音似乎在哀求。

儿子沉默片刻,他是在寻找更好的理由。 “妈,其实老人院并没有甚么不好?知道老
婆一但工作,一定没有时间好好服侍。老人院有吃有住有人服侍照顾, 不是比在家里
好得多吗?”

“可是,阿财叔他……”

洗了澡,草草吃了一碗方便面,儿子便到书房去。他茫然地伫立于窗前,有些犹豫不
决。母亲年轻便守寡,含辛茹苦将他抚养成人,供他出国读书。但她从不用年轻时的牺
牲当作要胁他孝顺的筹码,反而是妻子以婚姻要胁他!真的要让母亲住老人院吗?他问
自己,他有些不忍。 “可以陪你下半世的人是你老婆,难道是你妈吗?”阿财叔的儿
子总是这样提醒他。 “你妈都这么老了,好命的话可以活多几年,为何不趁这几年好
好孝顺她呢?树欲静而风不息,子欲养而亲不在啊!”亲戚总是这样劝他。儿子不敢再
想下去,深怕自己真的会改变初衷。

晚,太阳收敛起灼热的金光,躲在山后憩息。一间建在郊外山岗的一座贵族老人院。

是的,钱用得越多,儿子才心安理得。当儿子领着母亲步入大厅时,崭新的电视机,42
英寸的荧幕正播放着一部喜剧,但观众一点笑声也没有。

几个衣着一样,发型一样的老妪歪歪斜斜地坐在发沙上,神情呆滞而落寞。有个老人在
自言自语,有个正缓缓弯下腰,想去捡掉在地上的一块饼干吃。儿子知道母亲喜欢光
亮,所以为她选了一间阳光充足的房间。从窗口望出去,树荫下,一片芳草如茵。几名
护士推着坐在轮椅的老者在夕阳下散步,四周悄然寂静得令人心酸。纵是夕阳无限好,
毕竟已到了黄昏,他心中低低叹息。

“妈,我……我要走了!”母亲只能点头。他走时,母亲频频挥手,她张着没有牙的
嘴,苍白干燥的咀唇在嗫嚅着,一副欲语还休的样子。儿子这才注意到母亲银灰色的头
发,深陷的眼窝以及打着细褶的皱脸。母亲,真的老了!

他霍然记起一则儿时旧事。那年他才6岁,母亲有事回乡,不便携他同行,于是把他寄
住在阿财叔家几天。母亲临走时,他惊恐地抱着母亲的腿不肯放,伤心大声号哭道:
“妈妈不要丢下我!妈妈不要走!” 最后母亲没有丢下他。

他连忙离开房间,顺手把门关上,不敢回头,深恐那记忆像鬼魅似地追缠而来。

他回到家,妻子与岳母正疯狂的把母亲房里的一切扔个不亦乐乎。身高3英寸的奖杯
──那是他小学作文比赛《我的母亲》第1名的胜利品!华英字典──那是母亲整个月
省吃省用所买给他的第1份生日礼物!还有母亲临睡前要擦的风湿油,没有他为她擦,
带去老人院又有甚么意义呢?

“够了,别再扔了!”儿子怒吼道。

“这么多垃圾,不把它扔掉,怎么放得下我的东西。” 岳母没好气地说。

“就是嘛!你赶快把你妈那张烂床给抬出去,我明天要为我妈添张新的!”

一堆童年的照片展现在儿子眼前,那是母亲带他到动物园和游乐园拍的照片。

“它们是我妈的财产,一样也不能丢!”

“你这算甚态度?对我妈这么大声,我要你向我妈道歉!” (这算什么儿子,把自己
的母亲送到养老院,然后把岳母接来住,要就一起去送,要就留自己的母亲)

“我娶你就要爱你的母亲,为甚么?嫁给我就不能爱我的母亲?”

雨后的黑夜分外冷寂,街道萧瑟,行人车辆格外稀少。一辆宝马在路上飞驰,频频闯红
灯,陷黄格,呼一声又飞驰而过。那辆轿车一路奔往山岗上的那间老人院,停车直奔上
楼,推开母亲卧房的门。他幽灵似地站着,母亲正抚摸着风湿痛的双腿低泣。 她见到
儿子手中正拿着那瓶风湿油,显然感到安慰的说:“妈忘了带,幸好你拿来!”他走到
母亲身边,跪了下来。 “很晚了,妈自己擦可以了,你明天还要上班,回去吧!”

他嗫嚅片刻,终于忍不住啜泣道:“妈,对不起,请原谅我!我们回家去吧!”

~~后语~~

随着自己愈长大,看着父母亲脸庞从年轻变憔悴,头发从乌丝变白发,动作从迅捷变缓
慢,多心疼!父母亲总是将最好、最宝贵的留给我们,像蜡烛不停的燃烧自己,照亮孩
子!而我呢?有没有腾出一个空间给我的父母,或者只是在当我需要停泊岸时,才会想
起他们……

其实父母亲要的真的不多,只是一句随意的问候「爸、妈,你们今天好吗?」随意买的
宵夜,煮一顿再普通不过的晚餐,睡前帮他们盖盖被子,天冷帮他们添衣服、戴手套
….都能让他们高兴温馨很久。有时,我常在想:我希望我的子女以后如何对我。那现
在,我有没有如此对待我的父母?我相信,人是环环相扣的;现在,你如何对待你的父
母;以后,你的子女就如何待你。

朋友,人世间最难报的就是父母恩,愿我们都能:以反哺之心奉敬父母,以感恩之心孝
顺父母!

~共勉之~

生命不要求我们成为最好的,只要求我们作最大的努力!

老人安养院墙上发现的一篇文章

孩子!当你还很小的时候,我花了很多时间,教你慢慢用汤匙、用筷子吃东西。教你系
鞋带、扣扣子、溜滑梯、教你穿衣服、梳头发、拧鼻涕。这些和你在一起的点点滴滴,
是多么的令我怀念不已。所以,当我想不起来,接不上话时,请给我一点时间,等我一
下,让我再想一想……极可能最后连要说什么,我也一并忘记。孩子!你忘记我们练习
了好几百回,才学会的第一首娃娃歌吗?是否还记得每天总要我绞尽脑汁,去回答不知
道你从哪里冒出来的吗?所以,当我重复又重复说着老掉牙的故事,哼着我孩提时代的
儿歌时,体谅我。让我继续沉醉在这些回忆中吧!切望你,也能陪着我闲话家常吧!孩
子,现在我常忘了扣扣子、系鞋带。吃饭时,会弄脏衣服,梳头发时手还会不停的抖,
不要催促我,要对我多一点耐心和温柔,只要有你在一起,就会有很多的温暖涌上心
头。

孩子!如今,我的脚站也站不稳,走也走不动。所以,请你紧紧的握着我的手,陪着
我,慢慢的。就像当年一样,我带着你一步一步地走。

若为人子女也不懂得如何体谅他们,那他们便只能于痛苦中渡过余生,黑暗中逝去……

[今天你孝了没有?]

分类: 转载 标签:

FreeBSD Netgraph Interface Bonding

2010年7月21日 16hot 没有评论

The following is used on FreeBSD to combine two physical interfaces (fxp1, fxp2) into a single virtual interface (ngeth0). This method allows one to take the feeds from a traditional two-output tap and present a single virtual interface to NSM applications.

#!/bin/sh
kldload ng_ether
ifconfig fxp1 promisc -arp up
ifconfig fxp2 promisc -arp up

ngctl mkpeer . eiface hook ether
ngctl mkpeer ngeth0: one2many lower one
ngctl connect fxp1: ngeth0:lower lower many0
ngctl connect fxp2: ngeth0:lower lower many1

ifconfig ngeth0 -arp up

Remember to replace fxp1 and fxp2 with the interfaces on your FreeBSD system (e.g., em0, em1, etc.).

References

ngctl(8)
I believe I first heard of this technique here.

分类: BSD/linux, 转载 标签: ,

在 svn 的 post-commit hook 中使用 Gmail SMTP(转)

2010年6月3日 16hot 没有评论

Subversion 的 post-commit hook 是個很方便的功能,可以讓你在 commit 程式到 Repository 後,自動去做一些事。其中最有用的就是把 commit log 寄給相關的 developer。

在人人都有 Gmail 且 Gmail 也支援 SMTP 寄信的情況下,透過 Gmail 來寄出 commit log 應該是個好 idea。只不過, 目前的 mailer.py 並不支援 Gmail 的 TLS,所以下面的修改,就是要要將 mailer.py 修改成支援 TLS。

如果你是使用 Debian 或是 Ubuntu,請用 sudo apt-get install subversion-tools 將相關的 Subversion 工具裝到你的系統中。mailer.py 就在 /usr/share/subversion/hook-scripts/mailer 的目錄下。打開 mailer.py 找到 SMTPOutput class 中的 finish() menthod 將他改成(紅色是修改的部分):

def finish(self):
server = smtplib.SMTP(self.cfg.general.smtp_hostname)
if self.cfg.is_set(‘general.smtp_username’):
server.ehlo()
server.starttls()
server.ehlo()
server.login(self.cfg.general.smtp_username,
self.cfg.general.smtp_password)
server.sendmail(self.from_addr, self.to_addrs, self.buffer.getvalue())
server.close()

然後將,mailer.conf 的 [general] section 修改成下面的設定,並且放在你的 (svn repository)/conf 下:

[general]
smtp_hostname = smtp.gmail.com:587
smtp_username = your_gmail_account@gmail.com
smtp_password = your_gmail_password

這樣就成了。

分类: BSD/linux, 转载 标签:

一颗璀璨的月光宝石–Lua(转)

2010年5月16日 16hot 没有评论

1993年在巴西里约热内卢天主教大学(Pontifical Catholic University of Rio de Janeiro in Brazil)诞生了一门编程语言,发明者是该校的三位研究人员,他们给这门语言取了个浪漫的名字——Lua,在葡萄牙语里代表美丽的月亮。事实证明她没 有糟蹋这个优美的单词,Lua语言正如它名字所预示的那样成长为一门简洁、优雅且富有乐趣的语言。

Lua从一开始就是作为一门方便嵌入(其它应用程序)并可扩展的轻量级脚本语言来设计的,因此她一直遵从着简单、小巧、可移植、快速的原则,官 方实现完全采用ANSI C编写,能以C程序库的形式嵌入到宿主程序中。Lua的每个版本都保持着开放源码的传统,不过各版采用的许可协议并不相同,自5.0版(最新版是5.1) 开始她采用的是著名的MIT许可协议。正由于上述特点,所以Lua在游戏开发、机器人控制、分布式应用、图像处理、生物信息学等各种各样的领域中得到了越 来越广泛的应用。其中尤以游戏开发为最,许多著名的游戏,比如Escape from Monkey Island、World of Warcraft、大话西游,都采用了Lua来配合引擎完成数据描述、配置管理和逻辑控制等任务。

作为一门过程型动态语言,Lua有着如下的特性:

1、变量名没有类型,值才有类型,变量名在运行时可与任何类型的值绑定;

2、语言只提供唯一一种数据结构,称为表(table),它类似key-value关联数组,可以用任何类型的值作为key和value。提供 了一致且富有表达力的表构造语法,使得Lua很适合描述复杂的数据;

3、函数是一等类型,支持匿名函数和正则尾递归(proper tail recursion);

4、支持词法定界(lexical scoping)和闭包(closure);

5、提供thread类型和结构化的协程(coroutine)机制,在此基础上可方便实现协作式多任务;

6、运行期能编译字符串形式的程序文本并载入虚拟机执行;

7、通过元表(metatable)和元方法(metamethod)提供动态元机制(dynamic meta-mechanism),从而允许程序运行时根据需要改变或扩充语法设施的内定语义;

8、能方便地利用表和动态元机制实现基于原型(prototype-based)的面向对象模型;

9、从5.1版开始提供了完善的模块机制,从而更好地支持开发大型的应用程序;

Lua的语法类似PASCAL和Modula但更加简洁,所有的语法产生式规则(EBNF)不过才60几个。熟悉C和PASCAL的程序员一般 只需半个小时便可将其完全掌握。而在语义上Lua则与Scheme极为相似,她们完全共享上述的1、3、4、6点特性, Scheme的continuation与协程也基本相同只是自由度更高。最引人注目的是,两种语言都只提供唯一一种数据结构:Lua的表和Scheme 的列表(list)。正因为如此,有人甚至称Lua为“只用表的Scheme”。 阅读全文…

分类: LUA, 转载 标签:

jQuery操作input(转载)

2010年5月5日 16hot 没有评论
jQuery操作input
2009-10-14 15:10

获取选中的值
获取一组radio 被选中项的值
var item = $(‘input[@name=items][@checked]‘).val();

获取select被选中项的文本
var item = $(“select[@name=items] option[@selected]“).text();

select下拉框的第二个元素为当前选中值
$(‘#select_id’)[0].selectedIndex = 1;

radio单选组的第二个元素为当前选中值
$(‘input[@name=items]‘).get(1).checked = true;

获取值:
文本框,文本区域:
$(“#txt”).attr(“value”);

$(“#txt”).val();

多选框checkbox:
$(“#checkbox_id”).attr(“value”);

单选组radio:
$(“input[@type=radio][@checked]“).val();

下拉框select:
$(‘#sel’).val();

控制表单元素:
文本框,文本区域:

$(“#txt”).attr(“value”,”);//清空内容
$(“#txt”).attr(“value”,’11′);//填充内容

多选框checkbox:
$(“#chk1″).attr(“checked”,”);//不打勾
$(“#chk2″).attr(“checked”,true);//打勾
if($(“#chk1″).attr(‘checked’)==undefined) //判断是否已经打勾

单选组radio:
$(“input[@type=radio]“).attr(“checked”,’2′);//设置 value=2的项目为当前选中项

下拉框select:
$(“#sel”).attr(“value”,’-sel3′);//设置value=-sel3的项目为当前选中项
$(“<optionvalue=’1′>1111</option><optionvalue=’2′> 2222</option>”).appendTo(“#sel”)//添加下拉框的option
$(“#sel”).empty();//清空下拉框

=====================

在 Jquery中,用$(“#id”)来获得页面的input元素, 其相当于document.getElementById(“element”)
但是,该获取 的是一个Jquery对象,而不是一个dom element对象.value是dom element对象的属性.所以,使用
$(“#id”).value 不能取到值
取值的方法如 下:
取值:val = $(“#id”)[0].value;
$(“#id”)[0].value = “new value”;
赋值:
$(“#id”)[0].value = “new value”;
或者$(“#id”).val(“new value”);

val = $(“#id”).attr(“value”);

阅读全文…

分类: PHP, 转载 标签:

Enable core dump in Linux and FreeBSD(转)

2010年4月26日 16hot 没有评论

Just a note.

You can enable core dump by:

[bash] edit /etc/profile

ulimit -c unlimited

[csh/tcsh] edit /etc/csh.cshrc

limit coredumpsize unlimited

You can disable core dump by:

[bash] edit /etc/profile

ulimit -c 0

[csh/tcsh] edit /etc/csh.cshrc

limit coredumpsize 0

On FreeBSD, you also need to check the setting of kern.coredump:

# sysctl -a |grep kern.coredump
kern.coredump: 0
# sysctl kern.coredump=1
kern.coredump: 0 -> 1
# sysctl -a | grep kern.coredump
kern.coredump: 1

You can enforce this setting in /etc/sysctl.conf

[2008/01/01] Thanks for the complement from gslin, kern.sugid_coredump controls the core dump for setuid/setgid process in FreeBSD.

分类: BSD/linux, 转载 标签: , ,

网站排障分析常用的命令 (转)

2010年4月23日 16hot 2 条评论

网站排障分析常用的命令

好久没有发贴了,
整理一些常用分析网站的小命令方便大家排障,内容均来源于网络。
如果你是初学者关于AWK应用技巧请参照论坛的脚本编程版块,
如果你是老手,什么好的命令集或者必杀技欢迎跟贴,丰富此贴!
TXT版:http://docs.linuxtone.org/webapp/webscan.txt
系统连接状态篇:
1.查看TCP连接状态
netstat -nat |awk ‘{print $6}’|sort|uniq -c|sort -rn

netstat -n | awk ‘/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}’ 或
netstat -n | awk ‘/^tcp/ {++state[$NF]}; END {for(key in state) print key,”\t”,state[key]}’
netstat -n | awk ‘/^tcp/ {++arr[$NF]};END {for(k in arr) print k,”\t”,arr[k]}’

netstat -n |awk ‘/^tcp/ {print $NF}’|sort|uniq -c|sort -rn

netstat -ant | awk ‘{print $NF}’ | grep -v ‘[a-z]‘ | sort | uniq -c

2.查找请求数请20个IP(常用于查找攻来源):
netstat -anlp|grep 80|grep tcp|awk ‘{print $5}’|awk -F: ‘{print $1}’|sort|uniq -c|sort -nr|head -n20

netstat -ant |awk ‘/:80/{split($5,ip,”:”);++A[ip[1]]}END{for(i in A) print A[i],i}’ |sort -rn|head -n20

3.用tcpdump嗅探80端口的访问看看谁最高
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F”.” ‘{print $1″.”$2″.”$3″.”$4}’ | sort | uniq -c | sort -nr |head -20

4.查找较多time_wait连接
netstat -n|grep TIME_WAIT|awk ‘{print $5}’|sort|uniq -c|sort -rn|head -n20

5.找查较多的SYN连接
netstat -an | grep SYN | awk ‘{print $5}’ | awk -F: ‘{print $1}’ | sort | uniq -c | sort -nr | more

6.根据端口列进程
netstat -ntlp | grep 80 | awk ‘{print $7}’ | cut -d/ -f1

网站日志分析篇1(Apache):

1.获得访问前10位的ip地址
cat access.log|awk ‘{print $1}’|sort|uniq -c|sort -nr|head -10
cat access.log|awk ‘{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}’

2.访问次数最多的文件或页面,取前20
cat access.log|awk ‘{print $11}’|sort|uniq -c|sort -nr|head -20

3.列出传输最大的几个exe文件(分析下载站的时候常用)
cat access.log |awk ‘($7~/\.exe/){print $10 ” ” $1 ” ” $4 ” ” $7}’|sort -nr|head -20

4.列出输出大于200000byte(约200kb)的exe文件以及对应文件发生次数
cat access.log |awk ‘($10 > 200000 && $7~/\.exe/){print $7}’|sort -n|uniq -c|sort -nr|head -100

5.如果日志最后一列记录的是页面文件传输时间,则有列出到客户端最耗时的页面
cat access.log |awk ‘($7~/\.php/){print $NF ” ” $1 ” ” $4 ” ” $7}’|sort -nr|head -100

6.列出最最耗时的页面(超过60秒的)的以及对应页面发生次数
cat access.log |awk ‘($NF > 60 && $7~/\.php/){print $7}’|sort -n|uniq -c|sort -nr|head -100

7.列出传输时间超过 30 秒的文件
cat access.log |awk ‘($NF > 30){print $7}’|sort -n|uniq -c|sort -nr|head -20

8.统计网站流量(G)
cat access.log |awk ‘{sum+=$10} END {print sum/1024/1024/1024}’

9.统计404的连接
awk ‘($9 ~/404/)’ access.log | awk ‘{print $9,$7}’ | sort

10. 统计http status.
cat access.log |awk ‘{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}'
cat access.log |awk '{print $9}'|sort|uniq -c|sort -rn

10.蜘蛛分析
查看是哪些蜘蛛在抓取内容。
/usr/sbin/tcpdump -i eth0 -l -s 0 -w - dst port 80 | strings | grep -i user-agent | grep -i -E 'bot|crawler|slurp|spider'

网站日分析2(Squid篇)

2.按域统计流量
zcat squid_access.log.tar.gz| awk '{print $10,$7}' |awk 'BEGIN{FS="[ /]"}{trfc[$4]+=$1}END{for(domain in trfc){printf "%s\t%d\n",domain,trfc[domain]}}'

效率更高的perl版本请到此下载:http://docs.linuxtone.org/soft/tools/tr.pl

数据库篇
1.查看数据库执行的sql
/usr/sbin/tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | egrep -i 'SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL'

系统Debug分析篇

1.调试命令
strace -p pid

2.跟踪指定进程的PID
gdb -p pid

更多的请参考:
http://bbs.linuxtone.org/forum-14-1.html

分类: BSD/linux, 转载 标签:

对DNS报文的理解

2010年3月30日 16hot 没有评论

在这段时间的学习中,我发现通过抓包来学习的方法不错,这样有助于更深刻的理解。下面是我对dns报文的一些理解。
学习了《tcp/ip 卷一》 dns域名系统这一章,下面通过spynet capturenet抓一些dns通信报文进行一下分析,以加深理解。
本人是在windows 上使用nslookup工具来产生的dns通信,见上图。
阅读全文…

分类: DNS, 转载 标签: