playsolo 发表于 2014-10-01 10:16

如何利用NGREP进行 SIP调试

本帖最后由 playsolo 于 2014-10-01 10:22 编辑

SIP调试

原文发表于 如何利用NGREP进行-SIP调试


asterCC呼叫中心系统是一个基于SIP通信的系统,与传统的电话系统相比,语音的传送基于IP网络,因此学会如何调试VoIP通信是网络管理员们必须掌握的技能之一。这里我们会逐步介绍一些VoIP调试工具,希望能够帮助大家更好的设计、维护语音通信和呼叫中心系统。

什么是ngrep


ngrep是网络版的grep,用于从网络中过滤特定的信息,这里我们学习如何利用ngrep来调试SIP系统。

NGREP安装

yum install -y ngrep

对于sip 最常用的命令格式为


ngrep -dany -qWbyline "" port 5060

http://cn.astercc.org/wp-content/uploads/2014/09/ngrep_any-1024x402.jpg


这个命令会输出到达该服务器5060端口的所有包,5060为sip的默认端口,这样所有sip包都会输出到屏幕
如果我们想看来自/发送到服务器astercc.org的包,命令为

ngrep -dany -qWbyline "" port 5060 and host astercc.org


http://cn.astercc.org/wp-content/uploads/2014/09/ngrep_astercc-1024x487.jpg


我们也可以使用正则表达式来过滤特定的信息,例如我想看来自分机astercc-1000的包



ngrep -dany -qWbyline "astercc-1000" port 5060 and host astercc.org

使用ngrep过滤信息时可以使用正则表达式,例如只想看到SIP REGISTER包


ngrep -deth0 -qWbyline "^REGISTER" port 5060


其中 ^REGISTER 表示以REGISTER开头的包
我们也可以指定对某个网卡(eth0)进行查询 例如


ngrep -deth0 -qWbyline "astercc-1000" port 5060

注意ngrep抓包的优先级高于iptables防火墙,如果ngrep中看到有包但是asterisk中看不到,则说明是iptables阻挡,需要检查iptables设置

使用ngrep我们也可以将输出保存到指定的文件,命令格式为


ngrep -W byline -d eth0 port 5060 -O capture_file

其他两个参数包括

[*]-t : 以 年/月/日 的格式显示每个包的时间戳
[*]-T: 以 +S.UUUUUU 的格式打印时间,用于表示两个包之间的时差
ASTERISK中的SIP调试


asterisk中查看sip包的方法为,登陆到linux系统,连接到asterisk控制台


asterisk -r

开启sip调试模式


sip set debug on


http://cn.astercc.org/wp-content/uploads/2014/09/asterisk_sip_debug-1024x498.jpg


查看指定ip


sip set debug ip 76.68.146.197

关闭sip调试模式


sip set debug off



http://cn.astercc.org/wp-content/uploads/2014/09/asterisk_sip_debug_off.jpg

总结ngrep命令使用方便,能够帮助我们快速定位问题,实际上ngrep不仅能够应用于sip协议,能够适用于任何明文传送的网络数据。





shjhcx 发表于 2015-11-27 10:19

学无止境,其乐无穷:victory:
页: [1]
查看完整版本: 如何利用NGREP进行 SIP调试