Question

Is it possible to make a single page web server with netcat tool in Windows, like the one that can be made in Linux with bash using this command? (shell script basicly):

while true;
    do { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html; } | nc -l 80; 
done

Thanks in advance.

EDIT:

The test index.html file that i'm using is this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii">
        <title>Hi.</title>
    </head>
    <body>
        <h1>Hi.</h1>
    </body>
</html>
Was it helpful?

Solution 3

Ok after sniffing some headers and messing a little around i managed to make it work using this:

FOR /L %%i IN (1,0,2) DO ( (type responce.txt & type index.html) | nc -l -p 80 )

//responce.txt
HTTP/1.1 200 OK
Content-Type: text/html

//index.html (see question edit above)

OTHER TIPS

Assuming you have a Windows version of nc, it should be possible to accomplish the same thing with this 3 line batch file:

:Start
(echo HTTP/1.1 200 OK & type index.html) | nc -l 80
goto :Start

Assuming you'd prefer a one-liner:

FOR /L %i IN (1,0,2) DO ( (echo HTTP/1.1 200 OK & type index.html) | nc -l -p 80 )

(For scripts, replace %i with %%i)

I got this to work with Netcat I found here

index.html had to have sufficient HTTP headers in it to function (like "Content-Type"), though, so it wasn't strictly an HTML document. I assume you've already got that part worked out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top