0

I got an assignment from my teacher to try and beat a bot which sends a number each time and I need to send the exact number, but faster. I wrote a bash script:

#!/bin/bash
while true; do
  nc ip port | grep "try to beat me:" | cut -d " "  -f5 | xclip
  xclip -o 
done

The thing is that xclip copies the number, but it doesn't send it to the server in netcatb— why?

  • What do you mean by "send it to the server"? – Jesse_b May 25 '18 at 13:36
  • when i connect in netcat to the IP and port I get a message "try to beat me:1002 " and i need to send back the same number – phil24 May 25 '18 at 13:38
  • 2
    Your xclip -o command should just print the clipboard out to stdout. How are you intending to send this port back to the server? Through some sort of protocol, messaging system, etc? – Jesse_b May 25 '18 at 13:42
1

If you want to interactively send and receive data over a socket using nc, you can do:

nc -c /path/to/your/script <host> <port>

All incoming nc data will be written to the script's input and the script's output will be passed to the socket.

This way, in the script you can read the number from stdin and directly print it to send it to the nc:

#!/bin/bash
while true; do
  grep "try to beat me:" | cut -d " "  -f5 | xclip
  xclip -o 
done
-1

I believe you may want something like:

#!/bin/bash
while true; do
  port=$(nc ip port | grep "try to beat me:" | cut -d " "  -f5)
  nc ip "$port" </dev/null
  sleep 1
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.