tcp, udp, process, thread count: for view ddcc attack , then send warning :return:
()
| 108 | return NET_IN, NET_OUT |
| 109 | |
| 110 | def tupd(): |
| 111 | ''' |
| 112 | tcp, udp, process, thread count: for view ddcc attack , then send warning |
| 113 | :return: |
| 114 | ''' |
| 115 | try: |
| 116 | if sys.platform.startswith("linux") is True: |
| 117 | t = int(os.popen('ss -t|wc -l').read()[:-1])-1 |
| 118 | u = int(os.popen('ss -u|wc -l').read()[:-1])-1 |
| 119 | p = int(os.popen('ps -ef|wc -l').read()[:-1])-2 |
| 120 | d = int(os.popen('ps -eLf|wc -l').read()[:-1])-2 |
| 121 | elif sys.platform.startswith("darwin") is True: |
| 122 | t = int(os.popen('lsof -nP -iTCP | wc -l').read()[:-1]) - 1 |
| 123 | u = int(os.popen('lsof -nP -iUDP | wc -l').read()[:-1]) - 1 |
| 124 | p = len(psutil.pids()) |
| 125 | d = 0 |
| 126 | for k in psutil.pids(): |
| 127 | try: |
| 128 | d += psutil.Process(k).num_threads() |
| 129 | except: |
| 130 | pass |
| 131 | |
| 132 | elif sys.platform.startswith("win") is True: |
| 133 | t = int(os.popen('netstat -an|find "TCP" /c').read()[:-1])-1 |
| 134 | u = int(os.popen('netstat -an|find "UDP" /c').read()[:-1])-1 |
| 135 | p = len(psutil.pids()) |
| 136 | # if you find cpu is high, please set d=0 |
| 137 | d = sum([psutil.Process(k).num_threads() for k in psutil.pids()]) |
| 138 | else: |
| 139 | t,u,p,d = 0,0,0,0 |
| 140 | return t,u,p,d |
| 141 | except: |
| 142 | return 0,0,0,0 |
| 143 | |
| 144 | def get_network(ip_version): |
| 145 | if(ip_version == 4): |