Skip to content

Instantly share code, notes, and snippets.

@archichen
archichen / reporter.sh
Last active February 2, 2021 14:49
一行命令生成所有占用端口及其进程报告|Generate a report for all occupied port and their program with a line command
# 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")}}'
https://webmail.intel.com/owa/