2

I'm trying to create some test network traffic by sending TCP traffic using netcat.

The issue is that the netcat command to receive TCP data doesn't end on its own, which makes perfect sense.

I'm wondering how I can have a script that continues running to the send portion of the TCP traffic. Something similar to:

#!/bin/bash

#Prepare to receive traffic
nc -vv -l -p 5000 > receiveData.txt

#Send traffic
nc -nvv localhost 5000 < sendData.txt

Obviously the script will never get to the #Send traffic line because the receive traffic never ends. I've been looking at methods for running functions in bash asynchronously, but nothing I've read seems to solve this problem.

1 Answer 1

2

How about just running receive traffic process in the background so that the other commands can be executed to?

# Prepare to receive traffic
# Running this process in the background so that the sending TCP traffic
# happens

nc -vv -l -p 5000 > receiveData.txt &

#Send traffic
nc -nvv localhost 5000 < sendData.txt
Sign up to request clarification or add additional context in comments.

1 Comment

I should have tried that before I asked, but I assumed that doing that would only allow me to run the script once, and then leave that listening port open. I forgot that if the send is successful it will close out the receive. Thanks....such an obvious solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.