Advertisement
Guest User

Untitled

a guest
Apr 1st, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Check that two arguments were provided
  4. if [ $# -ne 2 ]; then
  5. echo "Usage: $0 port1 port2"
  6. exit 1
  7. fi
  8.  
  9. # Set variables for the two ports
  10. port1=$1
  11. port2=$2
  12.  
  13. # Create bidirectional tunnel between the two ports using socat
  14. socat TCP-LISTEN:$port1,fork TCP:localhost:$port2 &
  15. socat TCP-LISTEN:$port2,fork TCP:localhost:$port1 &
  16.  
  17. # Redirect outgoing traffic from port1 to port2 using iptables
  18. iptables -t nat -A OUTPUT -p tcp --dport $port1 -j REDIRECT --to-port $port2
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement