Skip to content

Instantly share code, notes, and snippets.

@stoyanovgeorge
Last active July 17, 2019 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoyanovgeorge/13b0c170279e7e01d10198f99b32c151 to your computer and use it in GitHub Desktop.
Save stoyanovgeorge/13b0c170279e7e01d10198f99b32c151 to your computer and use it in GitHub Desktop.
Creates a multicast routing after the user inputs a valid network interface and then it lists the routing table.
#!/bin/bash
# Creating an array containing all network interfaces which are up
net_array=()
for iface in $(ifconfig | cut -d ' ' -f1| tr ':' '\n' | awk NF)
do
net_array+=("$iface")
done
unset "net_array[${#net_array[@]}-1]"
printf "\nPlease select the network interface you want to use:\n"
read -r net_iface
while ! [[ "${net_array[*]}" =~ (^| )"$net_iface"( |$) ]]; do # check if the user input is valid
echo "Please enter a valid network interface:"
read -r net_iface
done
sudo ip r a 224.0.0.0/3 dev "$net_iface"
ip r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment