A statement used to count the number of IP addresses connected to a port in linux
Source: Internet
Author: User
A statement used to count the number of IP addresses connected to a port in linux. to analyze a port connected to the current linux system, such as the number of all external IP addresses of port 80, sort and collect statistics, can do this: netstat-tn2 & gt;/dev/null | grep: 80 | grep & quot; ESTAB...
A statement used to count the number of IP addresses connected to a port in linux. to analyze a port connected to the current linux system, such as the number of all external IP addresses of port 80, sort and collect statistics, it works like this: netstat-tn 2>/dev/null | grep: 80 | grep "ESTABLISHED" | awk '{print $5}' | cut-d: -f 4 | sort | uniq-c | sort-nr | head www.2cto.com: 1) netstat-tn 2>/dev/null parameter t, show only tcp connection-n: show only numbers, it will show the form: tcp 0 0 64. 91. *. *: 80 114.198.236.100: 12763 TIME_WAIT tcp 0 0 64. 91. *. *: 80 175.136.226.244: 51950 TIME_WAIT tcp 0 0 64. 91. *. *: 80 175.136.226.244: 51951 TIME_WAIT tcp 0 0 64. 91. *. *: 23 202.127.210.2: 14517 TIME_WAIT tcp 0 0 64. 91. *. *: 80 149.238.193.121: 65268 TIME_WAIT tcp 0 0 64. 91. *. *: 80 114.198.236.100: 44088 ESTABLISHED tcp 0 0 64. 91. *. *: 80 bytes: 51952 TIME_WAIT www.2cto.com 2) but as long as established, grep "ESTABLISHED" 3) and then AWK: ffff: 114.198.236.100: 12763: ffff: comment: 51950: ffff: 175.136.226.244: 51951: ffff: 0000: 65268: ffff: 114.198.236.100: 44088: ffff: 175.136.226.244: 51952 4) then use cut to extract content, for the usage of CUT, see:
Http://www.2cto.com/ OS /201208/152057.html cut-d:-f 4 here with: separator, result: 114.198.236.100 175.136.226.244 175.136.226.244 2017114.198.236.100 then sort again, group, then, sort the most frequently connected rows in the front, and even run the head command to finish 3 175.136.226.244 2 114.198.236.100 1 149.238.193.121 or even wc-l, obtains the total number of external IP addresses of estabalished connected to port 80.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service