Created
December 6, 2014 20:49
-
-
Save valorin/10c953c73f0da5fbee2f to your computer and use it in GitHub Desktop.
Script to open and close Mosh ports in UFW
This file contains 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 | |
# Load active ports | |
PORTS=`lsof -i | grep mosh-serv | cut -f2 -d":"` | |
STATUS=`sudo ufw status` | |
# Add Rules for new ports | |
for PORT in $PORTS; do | |
echo $STATUS | grep "$PORT/udp" > /dev/null | |
if [ $? -gt 0 ]; then | |
echo "Allowing new port $PORT" | |
sudo ufw allow $PORT/udp > /dev/null | |
fi | |
done | |
# Remove closed ports | |
PORTS=`sudo ufw status | grep "^60.../udp" | cut -f1 -d"/" | sort | uniq` | |
OPEN=`lsof -i | grep mosh-serv` | |
for PORT in $PORTS; do | |
echo $OPEN | grep $PORT > /dev/null | |
if [ $? -gt 0 ]; then | |
echo "Removing closed port $PORT." | |
sudo ufw delete allow $PORT/udp > /dev/null | |
fi | |
done |
this is pure genius
THIS. Is why I love programming right here. You FUCKING ROCK. I love you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you