"netcat" verbose mode under "bash" problem

Hi.
I have to write a script under bash shell.
This script use nc utility.
Everything is working on the virtual server of the hosting provider.

Code:
BASH_VERSION='4.2.50(1)-release'
uname -a
FreeBSD web1126.nic.ru 8.1-RELEASE FreeBSD 8.3-RELEASE-p4 #4: Thu Jan 30 00:00:49 MSK 2014

In my script, nc utility is listening port 27050 for UDP-packets and receiving them. But my script have to know the IP-address and the port of sender of the packet, to answer to it with an acknowledge or with a message.
I write in bash command line: nc -ul 27050 -v 1>zxc.txt 2>err.txt. After this, incoming packets appearing in zxc.txt, but err.txt is clean. But in Linux the "-v" key makes nc to write something like this:
Code:
Received packet from 127.0.0.1:35373 -> 127.0.0.1:7878 (local).
How else can I check the IP and the port of incoming packet?
I think, the hosting provider, shouldn't give me the right to install any daemons.
 
Normally if you have a VPS you are responsible for updating the OS.

nc utility is listening port 27050 for UDP-packets and receiving them. But my script have to know the IP-address and the port of sender of the packet, to answer to it with an acknowledge or with a message.
There're are several nc versions out there which might differ in some details. You can try net/netcat and see if it works with that version (it's called netcat after installation). If you can get it installed on FreeBSD 8.1.

Ever considered writing a C program for your problem? Here's a good starting point which will get you about 95 % there: http://beej.us/guide/bgnet/output/html/multipage/clientserver.html#datagram
 
I don't think that my hoster www.nic.ru will stop his activities and rush to perform an update, after I tell him that my script not working...
Not because of your script. But they should because it's been End-of-Life for at least 3 years. And looking at the uname(1) output it hasn't been updated since August 2012. That basically means it's a severe security risk. Not only for their network but also for everybody else's.
 
Thank's for everybody, I rewrote my script on PHP, using functions:
Code:
socket_create(), socket_bind(), socket_recvfrom(), socket_sendto()
Till I have not many external devices to communicate, PHP is suit for me.
But this functions work, only then I start my script from cron. I think, in this case, script is running by PHP-module, being a part of apache.
Then I run this script from bash, writing php script_name, bash writes, that this functions is "unknown". I think, in that case, the script is running in CGI mode. May be, this modes of running a script have different files php.ini.
 
Back
Top