//View Tip #445
» My code is compiling
» User input timeout
» Vi mode in bash
» Keeping your Home Directory Organized
JMC
Similar Tips
» Version all unversioned files in an SVN checkout» My code is compiling
» User input timeout
» Vi mode in bash
» Keeping your Home Directory Organized
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Serve files on port 8080 for anybody from the directory from where you start this command:
:;while [ $? -eq 0 ];do nc -vlp 8080 -c'(r=read;e=echo;$r a b c;z=$r;while [ ${#z} -gt 2 ];do $r z;done;f=`$e $b|sed 's/[^a-z0-9_.-]//gi'`;h="HTTP/1.0";o="$h 200 OK\r\n";c="Content";if [ -z $f ];then($e $o;ls|(while $r n;do if [ -f "$n" ]; then $e "<a href=\"/$n\">`ls -gh $n`
";fi;done););elif [ -f $f ];then $e "$o$c-Type: `file -ib $f`\n$c-Length: `stat -c%s $f`";$e;cat $f;else $e -e "$h 404 Not Found\n\n404\n";fi)';done
:;while [ $? -eq 0 ];do nc -vlp 8080 -c'(r=read;e=echo;$r a b c;z=$r;while [ ${#z} -gt 2 ];do $r z;done;f=`$e $b|sed 's/[^a-z0-9_.-]//gi'`;h="HTTP/1.0";o="$h 200 OK\r\n";c="Content";if [ -z $f ];then($e $o;ls|(while $r n;do if [ -f "$n" ]; then $e "<a href=\"/$n\">`ls -gh $n`
";fi;done););elif [ -f $f ];then $e "$o$c-Type: `file -ib $f`\n$c-Length: `stat -c%s $f`";$e;cat $f;else $e -e "$h 404 Not Found\n\n404\n";fi)';done
Comments
Add your comment
Comments are currently disabled
#1
You know, there are these things called "scripts". It's amazing. You can put things to run in it. You can even put line breaks in! :)
Posted 2008-12-09 19:11:46
Yea, as starenkaa says:
http://www.shell-fu.org/lister.php?id=54
Much simpler and easier. If you really need it on port 8080 instead of Python's default 8000 that can be done as well.
------------
#!/usr/bin/python
import SimpleHTTPServer
import SocketServer
# minimal web server. serves files relative to the
# current directory.
PORT = 8080
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
http://www.shell-fu.org/lister.php?id=54
Much simpler and easier. If you really need it on port 8080 instead of Python's default 8000 that can be done as well.
------------
#!/usr/bin/python
import SimpleHTTPServer
import SocketServer
# minimal web server. serves files relative to the
# current directory.
PORT = 8080
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
Posted 2008-12-09 23:56:32

