diff --git a/source/tools/detect/net/mon_connect/README.md b/source/tools/detect/net/mon_connect/README.md index 3233d1055bcaaea86da289cde392272b4cbfab42..f558fc2484a80f2e42ed3552c1ffcb6fbac520b7 100644 --- a/source/tools/detect/net/mon_connect/README.md +++ b/source/tools/detect/net/mon_connect/README.md @@ -1,2 +1,5 @@ # 功能说明 监控并统计系统的网络连接信息 + +## 工具介绍 +通过使用bcc,监控并统计系统的网络连接信息。通过tcp_connect和udp_sendmsg两个追踪点,统计端口的发送情况,每10s输出in和out的tcp/udp连接数量情况。 \ No newline at end of file diff --git a/source/tools/detect/net/mon_connect/mon_connect.py b/source/tools/detect/net/mon_connect/mon_connect.py index 7d5415435f70ac7fa99a7cda40ba9b2f6c4cc6a3..d0b07a743c12ab5e6c76b6352482d389dd7fcdc0 100644 --- a/source/tools/detect/net/mon_connect/mon_connect.py +++ b/source/tools/detect/net/mon_connect/mon_connect.py @@ -57,7 +57,7 @@ class CconnAna(): for k, v in sorted(ihs.items(), key=lambda ihs: ihs[1].value, reverse=True): cIn += v.value if c: - print k.port, inet_ntop(AF_INET, pack("I", k.ip)).encode(), v.value + print(k.port, inet_ntop(AF_INET, pack("I", k.ip)).encode(), v.value) c -= 1 self.__b['in_port_var'].clear() ohs = self.__b['out_port_var'].items() @@ -72,10 +72,12 @@ class CconnAna(): for h in uhs: # print("port: count: ", h) cUdp += h[1].value - print("%s: sync %d in, %d out, %d udp, %d close" % (datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d %H:%M:%S"), cIn, cOut, cUdp, chs[0][1].value)) + if len(chs) > 0: + print("%s: sync %d in, %d out, %d udp, %d close" % (datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d %H:%M:%S"), cIn, cOut, cUdp, chs[0][1].value)) def mainLoop(self): + print("Press Ctrl+C to stop...") while 1: time.sleep(10) self._report()