cat file that contains escaped characters to netcat

0

I'm trying to test a webserver with some HTTP request written in a file.

GET / HTTP/1.1\r\n\r\n

Right now I'm feeding that file to netcat like this:

cat files | nc localhost 80

However, the \r\n in the files are transfered directly to webserver(resulting in 4 chars, i.e. '\','r','\','n'). How can I feed that file so that chars are escaped correctly?

Wei Shi

Posted 2011-09-27T22:09:00.963

Reputation: 735

Answers

1

\r\n are the codes used in a printf statement to generate CarridgeReturn/NewLine line endings used by DOS/Windows.

As you are using cat, you are using some variant of unix which only uses \n as line end. BUT you don't have to have that char appear in the file. Just try removing those values (leaving a real Newline at the end of the line).

Example test file now =

GET / HTTP/1.1
  blah-blah

GET / HTTP/1.1
  blah2

OR if you really must interpret the \r\n values embedded in the file, you can interpret the file with the printf utiltity, i.e.

$ cat printf_inputtest.txt
GET / HTTP/1.1\r\n\r\n
GET / HTTP/1.1\r\n\r\n
$ printf "$( < printf_inputtest.txt )"
GET / HTTP/1.1


GET / HTTP/1.1

$ 

I hope this helps.

shellter

Posted 2011-09-27T22:09:00.963

Reputation: 170

@Usavich : please see my final edits. I believe I have solved your problem exactly as requested. Good luck. – shellter – 2011-09-29T02:43:29.433