Skip to content

Instantly share code, notes, and snippets.

@gdamjan
Created August 10, 2011 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdamjan/1136520 to your computer and use it in GitHub Desktop.
Save gdamjan/1136520 to your computer and use it in GitHub Desktop.
enhanced the simple file sharing with python
#! /usr/bin/env python2
# -*- coding: utf-8 -*-
import os, socket
import BaseHTTPServer, SimpleHTTPServer
PORT = 9999
NAME = "File sharing"
HOSTNAME = "%s.local" % socket.gethostname()
URL = "http://%s:%d/" % (HOSTNAME, PORT)
### Try to publish a bookmark to the local network using the zeroconf protocol (Bonjour/Avahi)
try:
from subprocess import Popen, PIPE
avahi = Popen(['avahi-publish', '-s', '-f', NAME, '_http._tcp', str(PORT)],
stdin=PIPE, stdout=PIPE, stderr=PIPE)
except OSError:
# windows is an OSError
pass
httpd = BaseHTTPServer.HTTPServer(('', PORT), SimpleHTTPServer.SimpleHTTPRequestHandler)
try:
print u'Го сервирам %s на локација: %s' % (os.getcwd(), URL)
httpd.serve_forever()
except KeyboardInterrupt:
print u'Готово'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment