I am using below command to send some strings to udp listening server.
echo "A 192.168.192.168" | nc -u 192.168.2.1 1234
but the server is getting trailing '\n' in echoed string.
I have tried below command too, but failed
echo "A 192.168.192.168" | nc -uC 192.168.2.1 1234
How can I remove that trailing new line character ?? Do I have any special option in nc ??
Install Netcat/NcatLinux and macOS users can quickly check if a port is open in the terminal with pre-installed Nc (and Netcat on Linux). Windows users will need to install Netcat's successor, Ncat, made by the Nmap project. Both are good for seeing if a specific port is open on a local network, VPN, or server.
In netcat, Verbose is a mode which can be initiated using [-v] parameter. Now verbose mode generates extended information. Basically, we will connect to a server using netcat two times to see the difference between normal and verbose mode. The command is nc 192.168.17.43 21 -v.
echo
usually provides -n
flag. This is not standard.
string A string to be written to standard output. If the first operand is -n, or if any of the operands contain a backslash ( '\' ) char‐ acter, the results are implementation-defined.
On XSI-conformant systems, if the first operand is -n, it shall be treated as a string, not an option.
I would suggest using printf
printf "A 192.168.192.168" | nc -u 192.168.2.1 1234
printf
doesnt append a new line unless it is told to, and it's standard behavior.
Try using
echo -n
so
echo -n "A 192.168.192.168" | nc -u 192.168.2.1 1234
echo man page says: -n do not output the trailing newline
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With