• Uncategorized

About linux : Linux-Nertcatnc-Weird-output-formating-from-nc-Netcat

Question Detail

Could someone please explain the reason for the following formatting behaviour from the output of Netcat/nc. I can’t think of how to search for an answer on google else I would have.

Client

curl POST -d ‘{ “something” : true }’ 192.168.1.50:11111

curl: (6) Could not resolve host: POST
{"response": {"result": success}}%  

Server

echo -e $send_reply | nc -l 11111

POST / HTTP/1.1
Host: 192.168.1.50:11111
User-Agent: curl/7.77.0
Accept: */*
Content-Length: 22
Content-Type: application/x-www-form-urlencoded

{ "something" : true }

All good so far.

Now if on the server I try

received=`echo -e $send_reply | nc -l 11111`; echo -e $received

{ "something" : true }ion/x-www-form-urlencoded

echo -e $received | grep POST | cut -d ‘ ‘ -f1

POST

And trying a few variations

$ echo -e $received | grep POST | cut -d ' ' -f1-3
POST / HTTP/1.1

$ echo -e $received | grep POST | cut -d ' ' -f1-4
Host: HTTP/1.1

$ echo -e $received | grep POST | cut -d '{' -f1
Content-Type: application/x-www-form-urlencoded

$ echo -e $received | grep POST | cut -d '{' -f2
 "something" : true }

$ echo -e $received | grep "response"
$ echo -e $received | grep "something"
 { "something" : true }

$ echo -e $send_reply | nc -l 11111 > /tmp/nc.op; received=`cat /tmp/nc.op`; echo $received
{ "something" : true }ion/x-www-form-urlencoded

$ cat /tmp/nc.op 
POST / HTTP/1.1
Host: 192.168.1.50:11111
User-Agent: curl/7.77.0
Accept: */*
Content-Length: 22
Content-Type: application/x-www-form-urlencoded

{ "something" : true } 

Question Answer

No answer for now.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.