Introduction
In this project, you will learn how to create a Zsh script that monitors the network communication status of a specific port. The script will count the number of data packets transmitted and received on the specified port within a 3-second timeframe.
👀 Preview
## Example
$ sh /home/labex/project/netcheck.sh 22
Packages: 2
🎯 Tasks
In this project, you will learn:
- How to create a Zsh script that accepts a port number as an input parameter
- How to use the
tcpdump
command to capture and count the number of packets for the specified port
- How to set a 3-second timeout for the script execution using the
timeout
command
- How to output the count of packets in a user-friendly format
🏆 Achievements
After completing this project, you will be able to:
- Develop a script that can monitor the network communication status of a specific port
- Understand how to use common Linux commands like
tcpdump
and timeout
in a Zsh script
- Gain experience in writing and testing shell scripts to solve practical problems
Skills Graph
%%%%{init: {'theme':'neutral'}}%%%%
flowchart RL
shell(("`Shell`")) -.-> shell/ControlFlowGroup(["`Control Flow`"])
linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"])
linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"])
linux(("`Linux`")) -.-> linux/InputandOutputRedirectionGroup(["`Input and Output Redirection`"])
linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"])
shell(("`Shell`")) -.-> shell/BasicSyntaxandStructureGroup(["`Basic Syntax and Structure`"])
shell(("`Shell`")) -.-> shell/VariableHandlingGroup(["`Variable Handling`"])
shell(("`Shell`")) -.-> shell/AdvancedScriptingConceptsGroup(["`Advanced Scripting Concepts`"])
shell(("`Shell`")) -.-> shell/SystemInteractionandConfigurationGroup(["`System Interaction and Configuration`"])
shell/ControlFlowGroup -.-> shell/if_else("`If-Else Statements`")
linux/BasicFileOperationsGroup -.-> linux/wc("`Text Counting`")
linux/BasicSystemCommandsGroup -.-> linux/exit("`Shell Exiting`")
linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`")
linux/InputandOutputRedirectionGroup -.-> linux/pipeline("`Data Piping`")
linux/InputandOutputRedirectionGroup -.-> linux/redirect("`I/O Redirecting`")
linux/UserandGroupManagementGroup -.-> linux/set("`Shell Setting`")
shell/BasicSyntaxandStructureGroup -.-> shell/shebang("`Shebang`")
shell/BasicSyntaxandStructureGroup -.-> shell/comments("`Comments`")
shell/BasicSyntaxandStructureGroup -.-> shell/quoting("`Quoting Mechanisms`")
shell/VariableHandlingGroup -.-> shell/variables_decl("`Variable Declaration`")
shell/VariableHandlingGroup -.-> shell/variables_usage("`Variable Usage`")
shell/ControlFlowGroup -.-> shell/for_loops("`For Loops`")
shell/ControlFlowGroup -.-> shell/cond_expr("`Conditional Expressions`")
shell/ControlFlowGroup -.-> shell/exit_status("`Exit and Return Status`")
shell/AdvancedScriptingConceptsGroup -.-> shell/cmd_substitution("`Command Substitution`")
shell/AdvancedScriptingConceptsGroup -.-> shell/subshells("`Subshells and Command Groups`")
shell/AdvancedScriptingConceptsGroup -.-> shell/adv_redirection("`Advanced Redirection`")
shell/SystemInteractionandConfigurationGroup -.-> shell/shell_options("`Shell Options and Attributes`")
shell/SystemInteractionandConfigurationGroup -.-> shell/globbing_expansion("`Globbing and Pathname Expansion`")
subgraph Lab Skills
shell/if_else -.-> lab-301481{{"`Network Data Packet Statistics`"}}
linux/wc -.-> lab-301481{{"`Network Data Packet Statistics`"}}
linux/exit -.-> lab-301481{{"`Network Data Packet Statistics`"}}
linux/echo -.-> lab-301481{{"`Network Data Packet Statistics`"}}
linux/pipeline -.-> lab-301481{{"`Network Data Packet Statistics`"}}
linux/redirect -.-> lab-301481{{"`Network Data Packet Statistics`"}}
linux/set -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/shebang -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/comments -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/quoting -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/variables_decl -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/variables_usage -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/for_loops -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/cond_expr -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/exit_status -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/cmd_substitution -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/subshells -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/adv_redirection -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/shell_options -.-> lab-301481{{"`Network Data Packet Statistics`"}}
shell/globbing_expansion -.-> lab-301481{{"`Network Data Packet Statistics`"}}
end