Skip to content

Instantly share code, notes, and snippets.

@cmrfrd
Created December 28, 2022 04:12
Show Gist options
  • Save cmrfrd/fe8f61da076f8a4a751bf8fc8cb579a5 to your computer and use it in GitHub Desktop.
Save cmrfrd/fe8f61da076f8a4a751bf8fc8cb579a5 to your computer and use it in GitHub Desktop.
ipad_screen_mirror_server
#! /usr/bin/env nix-shell
#! nix-shell --quiet -p uxplay -i bash
set -ueo pipefail
## Clear any existing "DROP ME" rules
## ref: https://stackoverflow.com/a/63855690/12393422
while sudo iptables -L -n --line-number | grep "DROP ME" > /dev/null; do
sudo iptables -D INPUT $(sudo iptables -L -n --line-number | grep "DROP ME" | head -1 | awk '{print $1}');
done
LOCAL_CIDR=${1:-"192.168.0.0/16"}
open-port-tcp() {
local port=$1
echo "Opening tcp port $port from $LOCAL_CIDR ..."
sudo iptables \
-I INPUT \
-p tcp \
-s $LOCAL_CIDR \
--dport $port \
-j ACCEPT \
-m comment --comment "DROP ME"
}
close-port-tcp() {
local port=${1:-0}
echo "Closing tcp port $port from $LOCAL_CIDR ..."
sudo iptables \
-D INPUT \
-p tcp \
-s $LOCAL_CIDR \
--dport $port \
-j ACCEPT \
-m comment --comment "DROP ME"
}
open-port-udp() {
local port=$1
echo "Opening udp port $port from $LOCAL_CIDR ..."
sudo iptables \
-I INPUT \
-p udp \
-s $LOCAL_CIDR \
--dport $port \
-j ACCEPT \
-m comment --comment "DROP ME"
}
close-port-udp() {
local port=${1:-0}
echo "Closing udp port $port from $LOCAL_CIDR ..."
sudo iptables \
-D INPUT \
-p udp \
-s $LOCAL_CIDR \
--dport $port \
-j ACCEPT \
-m comment --comment "DROP ME"
}
open-port-tcp 7100
open-port-tcp 7000
open-port-tcp 7001
open-port-udp 6000
open-port-udp 6001
open-port-udp 7011
# Ensure port closes if error occurs.
trap "close-port-tcp 7100 && \
close-port-tcp 7000 && \
close-port-tcp 7001 && \
close-port-udp 6000 && \
close-port-udp 6001 && \
close-port-udp 7011
" EXIT
uxplay -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment