Created
March 22, 2023 03:14
-
-
Save myh-st/5380ae19db6cbb1afc0dd5373108c398 to your computer and use it in GitHub Desktop.
Simulate traffic to test Device42
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
#!/bin/bash | |
# Define array of IPs and ports | |
ips=("10.0.0.1" "10.0.0.2" "10.0.0.3") | |
ports=(80 8080 3306) | |
# Loop through the IPs and ports with a random sleep time | |
for ip in "${ips[@]}" | |
do | |
for port in "${ports[@]}" | |
do | |
sleep $(($RANDOM % 5 + 3)) | |
echo "Connecting to $ip on port $port" | |
nc -vz $ip $port | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a Shell script that defines an array of IP addresses and ports, loops through them and connects to each IP address on each port, with a random sleep time between each connection. Here's a breakdown of what each part of the script does:
#!/bin/bash
is called a shebang and defines the interpreter for this script as Bash.#
are comments and are ignored by the interpreter. They describe what the code does.ips
andports
arrays define a list of IP addresses and ports respectively.for
loops iterate through both arrays and executes the following code block for each combination of IP address and port:sleep
command waits for a random amount of time, between 3 and 7 seconds ($RANDOM % 5 + 3
). This is done to simulate real-world delays or network issues when connecting to servers.echo
command prints a message to the console indicating which IP and port is being connected to.nc
command is used to connect to the IP address on the specified port.-vz
options are passed to enable verbose output and tellnc
not to send any data after initiating the connection. This is often used to check whether a remote host is reachable and also for port scanning purposes.Overall, this script can be used to test connectivity to multiple servers at once, or to check if specific ports are open on a server.