A Simple File Sharing Server using Python

This is very easy and yet simple file sharing server. It’s just a one line (which composed of multiple lines) of codes which you can paste it anywhere to share the file with your coworkers easily or getting the file from the server. Here it is!

python -c 'import BaseHTTPServer; import CGIHTTPServer; import sys; import socket; s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.connect(("www.google.com",8000)); ipaddr = s.getsockname()[0]; s.close(); print "="*36 ; print "Access: " + ipaddr +":"+str(9999); print "="*36 ; server=BaseHTTPServer.HTTPServer ; handler = CGIHTTPServer.CGIHTTPRequestHandler; server_address = ("",int(9999)); httpd = server(server_address, handler); httpd.serve_forever()'

OK. That might be too confused. Let’s see closely in easy-to-understand multiple lines of codes.

import BaseHTTPServer
import CGIHTTPServer
import sys
import socket
def get_local_ip_address(target):
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  ipaddr = s.getsockname()[0]
  return ipaddr
print "="*36
print "Access: " + get_local_ip_address('www.google.com') +":"+str(9999)
print "="*36
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("",int(9999))
httpd = server(server_address, handler)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s