码迷,mamicode.com
首页 > 其他好文 > 详细

tcpping指定网卡类型为any结果不准确问题

时间:2016-05-15 19:54:46      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:linux tcpping探测

tcpping软件参考开源工具

https://github.com/jwyllie83/tcpping

该软件通过libnet组包和发包,通过libpcap抓取返回的ACK或RST信息来计算tcp延迟和丢包。

./tcpping -h

./tcpping: invalid option -- ‘h‘

./tcpping: [-v] [-c count] [-p port] [-i interval] [-I interface] [-t ttl] [-S srcaddress] remote_host


如果设备上有多个网卡,数据发出是从网卡A发出,数据回来是经过网卡B回来,这种情况下,需要设置-I any。只针对linux系统有效。

但设置成any后,第一包结果出现 异常。如:

./tcpping -S 1.1.1.1 1.1.1.5 -p 22 -I any

TCP PING 1.1.1.5 (1.1.1.5:22)

SYN/ACK from 1.1.1.5: seq=1 ttl=63 time=1463296896.000s

SYN/ACK from 1.1.1.5: seq=2 ttl=63 time=43.474ms

SYN/ACK from 1.1.1.5: seq=3 ttl=63 time=45.411ms

SYN/ACK from 1.1.1.5: seq=4 ttl=63 time=45.780ms

SYN/ACK from 1.1.1.5: seq=5 ttl=63 time=43.381ms

SYN/ACK from 1.1.1.5: seq=6 ttl=63 time=43.429ms

SYN/ACK from 1.1.1.5: seq=7 ttl=63 time=45.549ms

SYN/ACK from 1.1.1.5: seq=8 ttl=63 time=43.241ms

^C

--- 1.1.1.5 TCP ping statistics ---

7 SYN packets transmitted, 8 SYN/ACKs and 0 RSTs received, -14.3% packet loss

round-trip min/avg/max = 43.241/182912128.000/1463296896.000 ms


出现这种情况,稍微改一下tcpping.c代码即可

/* Do some analysis on the returned packet... */

if (ms > 1000) {

units = "s";

ms /= 1000;

            //如果大于1000,认为异常,直接返回

return;

}


改进后效果为:

./tcpping -S 1.1.1.1 1.1.1.5 -p 22 -I any -c 5

TCP PING 1.1.1.5 (1.1.1.5:22)

SYN/ACK from 1.1.1.5: seq=1 ttl=63 time=43.492ms

SYN/ACK from 1.1.1.5: seq=2 ttl=63 time=43.469ms

SYN/ACK from 1.1.1.5: seq=3 ttl=63 time=45.379ms

SYN/ACK from 1.1.1.5: seq=4 ttl=63 time=43.549ms

SYN/ACK from 1.1.1.5: seq=5 ttl=63 time=43.409ms

SYN/ACK from 1.1.1.5: seq=6 ttl=63 time=43.494ms


--- 1.1.1.5 TCP ping statistics ---

6 SYN packets transmitted, 6 SYN/ACKs and 0 RSTs received, 0.0% packet loss

round-trip min/avg/max = 43.409/43.799/45.379 ms


tcpping指定网卡类型为any结果不准确问题

标签:linux tcpping探测

原文地址:http://zhuminghui.blog.51cto.com/3838075/1773658

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!