pyWebServer.py
import http.server
import socketserver
import socket
def get_host_ip():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
finally:
s.close()
PORT = 80
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("Made BY PXW")
print("serving at port", PORT)
print(get_host_ip())
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
print("同一个局域网,浏览器输入ip:",ip,"就可以分享这个应用所在目录所有文件.")
httpd.serve_forever()
浏览器输入ip
适用 pyinstaller -c -F ****.py
就可以打包生成*****.exe文件了。