#!/bin/sh tee /bin/port /usr/bin/port > /dev/null << 'EOF' #!/bin/sh PORTS_FILE="/ports.txt" add_port() { local local_port="$1" if [ -z "$local_port" ]; then echo "Please provide a local port to forward." exit 1 fi if grep -q ":${local_port}$" "$PORTS_FILE" 2>/dev/null; then echo "Port ${local_port} is already forwarded." exit 1 fi random_port=$(shuf -i 1-65535 -n 1) while [ "$random_port" -eq 22 ]; do random_port=$(shuf -i 1-65535 -n 1) done ssh -o StrictHostKeyChecking=no -f -N -R 0.0.0.0:"${random_port}":localhost:"${local_port}" user@virtual-net.kvm-i7.host > /dev/null & echo "${random_port}:${local_port}" >> "$PORTS_FILE" echo "${local_port} is now on virtual-net.kvm-i7.host:${random_port}" } remove_port() { local local_port="$1" if [ -z "$local_port" ]; then echo "Please provide a local port to remove." exit 1 fi random_port=$(grep ":${local_port}$" "$PORTS_FILE" 2>/dev/null | cut -d":" -f1) if [ -z "$random_port" ]; then echo "Port ${local_port} not found." exit 1 fi pkill -f "ssh -o StrictHostKeyChecking=no -f -N -R ${random_port}:localhost:${local_port} user@virtual-net.kvm-i7.host" > /dev/null sed -i "/${random_port}:${local_port}/d" "$PORTS_FILE" > /dev/null echo "Port ${local_port} has been removed." } refresh_ports() { if [ ! -f "$PORTS_FILE" ]; then echo "No ports to refresh." exit 1 fi while IFS= read -r line; do random_port=$(echo "$line" | cut -d":" -f1) local_port=$(echo "$line" | cut -d":" -f2) ssh -o StrictHostKeyChecking=no -f -N -R "${random_port}":localhost:"${local_port}" user@virtual-net.kvm-i7.host > /dev/null & done < "$PORTS_FILE" echo "Ports have been successfully restarted." } list_ports() { if [ ! -f "$PORTS_FILE" ]; then echo "No ports to list." exit 1 fi echo "Current port mappings:" while IFS= read -r line; do random_port=$(echo "$line" | cut -d":" -f1) local_port=$(echo "$line" | cut -d":" -f2) echo "Local port ${local_port} -> Public port ${random_port} (virtual-net.kvm-i7.host)" done < "$PORTS_FILE" } case "$1" in add) add_port "$2" ;; remove) remove_port "$2" ;; refresh) refresh_ports ;; list) list_ports ;; *) echo "Usage: $0 {add|remove|refresh|list} [port]" exit 1 ;; esac EOF chmod +x /bin/port /usr/bin/port clear echo "Welcome to your shared IPv4, Please use the port command to see what commands with port you can do! For example to add port 80, run port add 80."