How to view Linux network port traffic

Source: Internet
Author: User

The rapid development of Linux has caught up with Microsoft in just a short time, So Microsoft has paid attention to this opponent. Maybe you are learning Linux. Here we will explain how to check the script of Linux network port traffic, I hope to learn how to view the Linux network port traffic script. Through this script, we found that bash is indeed more powerful than the old shell in arithmetic operations. Therefore, we need to start learning bash to use its powerful functions. However, the for statement function in bash differs significantly from that in c.

 
 
  1. # Cat stream
  2.  
  3. #! /Bin/bash
  4. # Write by Neil. xu qq: 37391319 email: xurongzhong@gmail.com
  5. #2008-8-19 we need to monitor streams of LTS channels, so write this
  6. Typeset in in_old dif_in dif_in1 dif_out1
  7. Typeset out out_old dif_out
  8.  
  9. In_old= $ (Cat/proc/net/dev | grep eth0 | sed'S= ^ .*:= '| Awk' {print $1 }')
  10. Out_old= $ (Cat/proc/net/dev | grep eth0 | sed'S= ^ .*:= '| Awk' {print $9 }')
  11.  
  12. While true
  13. Do
  14. Sleep 1
  15. In= $ (Cat/proc/net/dev | grep eth0 | sed'S= ^ .*:= '| Awk' {print $1 }')
  16. Out= $ (Cat/proc/net/dev | grep eth0 | sed'S= ^ .*:= '| Awk' {print $9 }')
  17. Dif_in= $ (In-in_old ))
  18. Dif_in1= $ (Dif_in * 8/1024/1024 ))
  19. Dif_out= $ (Out-out_old ))
  20. Echo "IN :$ {dif_in} bytes OUT :$ {dif_out} bytes"
  21. Dif_out1= $ (Dif_out * 8/1024/1024 ))
  22. Echo "IN :$ {dif_in1} mbps OUT :$ {dif_out1} mbps"
  23. In_old=$ {In}
  24. Out_old=$ {Out}
  25. Done
  26.  
  27. Running effect:
  28. #./Stream
  29. IN: 349179 bytes OUT: 1363936 bytes
  30. IN: 2 mbps OUT: 10 mbps
  31. IN: 349612 bytes OUT: 1361852 bytes
  32. IN: 2 mbps OUT: 10 mbps
  33. IN: 348684 bytes OUT: 1358952 bytes
  34. IN: 2 mbps OUT: 10 mbps
  35. IN: 349998 bytes OUT: 1359092 bytes

In this way, you can learn how to view the Linux network port traffic.

  1. Analysis of Open-source Cisco router virtual machines in Linux
  2. 30 Linux releases
  3. Learning Experience: Linux File lock
  4. Linux Extension File System
  5. Easily create a file system in Linux

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.