Results 1 to 5 of 5
Hi all,
I'm trying to do some experiments with net cat, i want to send a file via for several times and I want to measure throughput. The problem is ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-07-2013 #1Just Joined!
- Join Date
- Feb 2013
- Posts
- 11
checking whether server is listening or not with netcat
Hi all,
I'm trying to do some experiments with net cat, i want to send a file via for several times and I want to measure throughput. The problem is that each time Client and server are connected and sending is done, the connection is closed and I server should listen again. Consider following commands:
andCode:[root vm1]# nc -l 12345 > /dev/null
each time I should run the commandCode:[root vm2 ~]# dd if=/dev/zero bs=2000 count=500 | nc -v 192.168.122.193 12345
again, I cannot put this command in a loop. I tried it and I got :Code:[root vm1]# nc -l 12345 > /dev/null
How can I automate this?Code:nc -l 12345 > /dev/null nc: getaddrinfo: Servname not supported for ai_socktype nc -l 12345 > /dev/null nc: getaddrinfo: Servname not supported for ai_socktype nc -l 12345 > /dev/null .........
- 02-07-2013 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,160
The -l port option turns nc into a server, so you should not need to restart it (which is why you are getting errors in the last examples of your post) unless you give it a timeout option and the timeout expires. IE, start nc -l port and then on the other host you can do the dd | nc as often as you want, though bear in mind that nc will handle multiple connections at the same time, so if one is not finished sending, and you start another, your timing results will be skewed.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 02-07-2013 #3Just Joined!
- Join Date
- Feb 2013
- Posts
- 11
That is not my case, server stop after first onnection for e.g second time I got this error in the client:
Code:nc: connect to 192.168.122.193 port 12345 (tcp) failed: Connection refused
- 02-07-2013 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,160
This (from the nc man page) may help:
Code:-k Forces nc to stay listening for another connection after its current connection is completed. It is an error to use this option without the -l option.Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 02-07-2013 #5Just Joined!
- Join Date
- Feb 2013
- Posts
- 11
Thanks a lot for your help. It worked.


Reply With Quote
