在开发中经常有个需求,正在连接tcp,想要让他异常断开来测试重连机制,这肯定不能杀死进程,一直有这个问题,今天发现了一个工具tcpkill,有了它测试tcp重连如此简单。

ubunt环境:

$ sudo apt-get install dsniff

$ tcpkill [-i interface] [-1...9] expression

 

  • 用netstat -ano查看连接:
netstat -nao | grep 6321
tcp        0      0 10.12.50.13:31902     10.60.58.41:6000       ESTABLISHED keepalive (243.19/0/0)
tcp        0      0 10.12.50.13:31910     10.60.58.41:6000       ESTABLISHED keepalive (243.18/0/0)
tcp        0      0 10.12.50.13:31919     10.60.58.41:6000       ESTABLISHED keepalive (243.18/0/0)
tcp        0      0 10.12.50.13:31926     10.60.58.41:6000       ESTABLISHED keepalive (244.20/0/0)
tcp        0      0 10.12.50.13:31904     10.60.58.41:6000       ESTABLISHED keepalive (243.18/0/0)
tcp        0      0 10.12.50.13:31604     10.60.58.41:6000       ESTABLISHED keepalive (245.22/0/0)
tcp        0      0 10.12.50.13:31592     10.60.58.41:6000       ESTABLISHED keepalive (237.03/0/0)
  • 下面就是杀死6000进程连接的方法了
    sudo tcpkill -i eth1 -9 port 6321

     

转载于:https://my.oschina.net/u/2342726/blog/1556289

Logo

更多推荐