-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzero.py
64 lines (64 loc) · 1.49 KB
/
zero.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python3
import tkinter
from zeroconf import IPVersion, ServiceInfo, Zeroconf
import qrcode
import socket
import uploadserver
from os import chdir, getcwd
import threading
import time
from tkinter import filedialog
print("Change Dir? (y/n)")
a = input("#")
DIRECTORY = getcwd()
if (a.lower() == 'y'):
root = tkinter.Tk()
root.wm_withdraw()
DIRECTORY = filedialog.askdirectory()
root.destroy()
dir = getcwd()
print(dir)
chdir('../')
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = (s.getsockname()[0])
s.close()
print(f"Current IP : {ip}")
url = "http://" + ip + ":8000"
print("----- UPLOAD SERVER -----")
qr2 = qrcode.QRCode()
qr2.add_data(url + "/upload")
qr2.print_ascii()
print("----- DOWNLOAD SERVER -----")
qr = qrcode.QRCode()
qr.add_data(url)
qr.print_ascii()
print()
print(url)
print()
chdir(DIRECTORY)
website = threading.Thread(target=uploadserver.main, daemon=True)
website.start()
ip_version = IPVersion.V4Only
desc = {'URL': f'http://{ip}:8000'}
info = ServiceInfo(
"_http._tcp.local.",
f"{socket.gethostname()}._http._tcp.local.",
addresses=[ip],
port=8000,
properties=desc,
server="ash-2.local.",
)
zeroconf = Zeroconf(ip_version=ip_version)
print("Registration of a service, press Ctrl-C to exit...")
zeroconf.register_service(info)
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
finally:
print("Unregistering...")
zeroconf.unregister_service(info)
zeroconf.close()
time.sleep(1)