-
-
Save Arryboom/f1fd10af56be30f2c0fba9dbaad6abbf to your computer and use it in GitHub Desktop.
一行命令生成所有占用端口及其进程报告|Generate a report for all occupied port and their program with a line command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Choose one command, Copy it and execute, no need for execute reporter.sh file. | |
# Report file was place at /tmp/reporter.csv|md | |
# CSV version | |
# Preview: https://imgur.com/c5E0T1v | |
netstat -ntlp | awk 'BEGIN{ system("echo IP, Port, PID, Parameter > /tmp/reporter.csv") } NR>2 {if($4 !~ "::" && $7 != "-"){split($4,ipAndPort,":"); split($7,pidAndProgress,"/"); system("echo "ipAndPort[1]","ipAndPort[2]","pidAndProgress[1]", `cat /proc/"pidAndProgress[1]"/cmdline` >> /tmp/reporter.csv")}}' | |
# Markdown version | |
# Preview: https://imgur.com/ivmUhgu | |
netstat -ntlp | awk 'BEGIN{ system("echo \\|IP\\|Port\\|PID\\|Parameter\\| > /tmp/reporter.md; echo \\|-\\|-\\|-\\|-\\| >> /tmp/reporter.md") } NR>2 {if($4 !~ "::" && $7 != "-"){split($4,ipAndPort,":"); split($7,pidAndProgress,"/"); system("echo \\|"ipAndPort[1]"\\|"ipAndPort[2]"\\|"pidAndProgress[1]"\\|`cat /proc/"pidAndProgress[1]"/cmdline`\\| >> /tmp/reporter.md")}}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment