Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
lkiefer
vnclic
Commits
b33f9390
Commit
b33f9390
authored
Aug 18, 2020
by
lkiefer
Browse files
better management of network problems
parent
49d7da0f
Changes
5
Hide whitespace changes
Inline
Side-by-side
builddeb.sh
100644 → 100755
View file @
b33f9390
python3 setup.py
--command-packages
=
stdeb.command bdist_deb
echo
"Press enter to continue"
read
bye
deb_dist/python3-vnclic_0.1.1-1_all.deb
0 → 100644
View file @
b33f9390
File added
setup.py
View file @
b33f9390
...
...
@@ -3,10 +3,10 @@ from setuptools import setup
setup
(
name
=
"vnclic"
,
version
=
"0.1"
,
version
=
"0.1
.1
"
,
author
=
"Ludovic Kiefer"
,
author_email
=
"dev@lkiefer.org"
,
description
=
"Screen sharing on LAN
network
"
,
description
=
"Screen sharing on LAN"
,
license
=
"GNU GPL v2"
,
url
=
"https://framagit.org/lkiefer/vnclic"
,
packages
=
[
'vnclic'
],
...
...
vnclic/network.py
View file @
b33f9390
...
...
@@ -37,22 +37,33 @@ class UDPServer(threading.Thread):
def
__init__
(
self
,
port
,
interface
=
False
):
threading
.
Thread
.
__init__
(
self
)
self
.
setDaemon
(
True
)
self
.
ip
=
getIP
()
print
(
"My IP address: "
+
self
.
ip
);
self
.
s
=
socket
(
AF_INET
,
SOCK_DGRAM
)
self
.
s
.
bind
((
''
,
port
))
self
.
status
=
1
self
.
interface
=
interface
try
:
self
.
s
.
bind
((
''
,
port
))
self
.
status
=
1
self
.
interface
=
interface
except
:
self
.
status
=
0
interface
.
message
(
self
.
status
)
def
run
(
self
):
while
self
.
status
:
while
self
.
status
==
1
:
m
=
self
.
s
.
recvfrom
(
4096
)
data
=
m
[
0
].
decode
(
"Utf8"
)
host
=
m
[
1
][
0
]
if
self
.
interface
:
self
.
interface
.
receive
(
data
,
host
)
if
host
==
self
.
ip
:
print
(
"Dropped"
)
else
:
self
.
interface
.
receive
(
data
,
host
)
else
:
print
(
"
\n
Received: "
,
data
)
print
(
"
\n
From: "
,
host
)
def
stop
(
self
):
self
.
status
=
0
...
...
@@ -60,18 +71,19 @@ class UDPServer(threading.Thread):
class
UDPClient
(
threading
.
Thread
):
"Send UDP messages on the network"
def
__init__
(
self
,
port
,
interface
=
False
):
def
__init__
(
self
,
port
):
threading
.
Thread
.
__init__
(
self
)
self
.
setDaemon
(
True
)
self
.
s
=
socket
(
AF_INET
,
SOCK_DGRAM
)
self
.
s
.
setsockopt
(
SOL_SOCKET
,
SO_BROADCAST
,
1
)
self
.
port
=
port
if
interface
:
interface
.
threadParler
(
self
)
def
send
(
self
,
message
,
address
=
"255.255.255.255"
):
"Send broadcast (default) or unicast (if address specified) messages"
self
.
s
.
sendto
(
message
.
encode
(
"Utf8"
),(
address
,
self
.
port
))
try
:
self
.
s
.
sendto
(
message
.
encode
(
"Utf8"
),(
address
,
self
.
port
))
except
:
print
(
'UDPClient : Not connected.'
)
class
Cron
(
threading
.
Thread
):
"Execute an action every few seconds"
...
...
vnclic/vnclic.py
View file @
b33f9390
...
...
@@ -39,7 +39,7 @@ class VnClic(object):
def
__init__
(
self
,
args
=
None
):
self
.
w
=
Tk
()
self
.
w
.
title
(
'vnclic'
)
# Folder containing the program files
self
.
pathname
=
sys
.
path
[
0
]
# an object to manage preferences (load, save...)
...
...
@@ -54,18 +54,14 @@ class VnClic(object):
just delete the .vnclic.conf file in your home folder."
,
width
=
300
,
relief
=
FLAT
)
sys
.
exit
(
0
)
self
.
connect
()
self
.
user_list
=
{}
self
.
ip
=
getIP
()
print
(
"Mon ip: "
+
self
.
ip
);
self
.
connect
()
self
.
started
=
False
self
.
mainWindow
()
self
.
w
.
mainloop
()
def
mainWindow
(
self
):
# Main frame
sidebar
=
Frame
(
self
.
w
)
...
...
@@ -75,7 +71,7 @@ class VnClic(object):
topbar
.
pack
(
side
=
TOP
,
padx
=
4
)
Button
(
topbar
,
text
=
"Quitter"
,
command
=
self
.
quit
).
pack
(
side
=
RIGHT
,
padx
=
4
)
# Start or stop screen sharing
f_toggle
=
Frame
(
topbar
)
f_toggle
.
pack
(
side
=
RIGHT
,
padx
=
4
,
pady
=
4
)
...
...
@@ -85,12 +81,10 @@ class VnClic(object):
self
.
btn_stop
.
pack
(
side
=
TOP
)
self
.
btn_stop
.
pack_forget
()
optionbar
=
Frame
(
sidebar
,
relief
=
GROOVE
,
borderwidth
=
3
)
optionbar
.
pack
(
side
=
TOP
,
padx
=
4
,
anchor
=
NW
,
fill
=
X
)
Label
(
optionbar
,
text
=
"Options:"
).
pack
(
side
=
TOP
,
padx
=
4
,
pady
=
4
)
self
.
name
=
StringVar
()
self
.
name
.
set
(
self
.
preference
[
'Server'
].
get
(
'name'
))
if
self
.
name
.
get
()
==
""
:
...
...
@@ -99,7 +93,7 @@ class VnClic(object):
f_name
.
pack
(
side
=
TOP
)
Label
(
f_name
,
text
=
"Nom:"
).
pack
(
side
=
LEFT
,
padx
=
4
,
pady
=
4
)
Entry
(
f_name
,
textvariable
=
self
.
name
).
pack
(
side
=
LEFT
,
padx
=
4
)
self
.
autoconnect
=
BooleanVar
()
self
.
autoconnect
.
set
(
self
.
preference
[
'Client'
].
getboolean
(
'autoconnect'
))
#self.autoconnect.set(True)
...
...
@@ -109,7 +103,6 @@ class VnClic(object):
Checkbutton
(
optionbar
,
text
=
"Partager le clavier et la souris"
,
variable
=
self
.
input
,
command
=
self
.
setViewonly
).
pack
(
side
=
TOP
,
padx
=
4
)
Button
(
optionbar
,
text
=
"Enregistrer"
,
command
=
self
.
save
).
pack
(
side
=
RIGHT
,
padx
=
4
)
self
.
userbar
=
Frame
(
sidebar
,
relief
=
GROOVE
,
borderwidth
=
3
)
self
.
userbar
.
pack
(
side
=
TOP
,
padx
=
4
,
anchor
=
NW
,
fill
=
X
)
Label
(
self
.
userbar
,
text
=
"Voir l'écran de:"
).
pack
(
side
=
TOP
,
padx
=
4
,
pady
=
4
)
...
...
@@ -119,26 +112,34 @@ class VnClic(object):
self
.
preference
[
'Port'
][
'vnclic'
]
+
" et "
+
self
.
preference
[
'Port'
][
'vnc'
]
+
"."
,
width
=
300
,
relief
=
FLAT
)
self
.
messageUser
()
def
showError
(
self
,
message
=
""
):
Message
(
self
.
w
,
text
=
message
,
width
=
300
,
relief
=
FLAT
).
pack
(
side
=
TOP
,
padx
=
4
)
Button
(
self
.
w
,
text
=
"Quitter"
,
command
=
self
.
quit
).
pack
(
side
=
TOP
,
padx
=
4
)
def
connect
(
self
):
self
.
server
=
UDPServer
(
self
.
preference
[
'Port'
].
getint
(
'vnclic'
),
self
)
print
(
"serveur lancé"
)
self
.
client
=
UDPClient
(
self
.
preference
[
'Port'
].
getint
(
'vnclic'
))
self
.
server
.
start
()
self
.
client
.
start
()
print
(
"### connecté"
)
def
start
(
self
):
"Start sharing screen"
#self.server = subprocess.run(["x11vnc", "-gui", "tray"])
if
self
.
input
.
get
():
self
.
vnc_server
=
subprocess
.
Popen
([
"x11vnc"
,
"-gui"
,
"tray"
,
"-shared"
,
"-noviewonly"
])
self
.
vnc_server
=
subprocess
.
Popen
([
"x11vnc"
,
"-shared"
,
"-noviewonly"
])
else
:
self
.
vnc_server
=
subprocess
.
Popen
([
"x11vnc"
,
"-gui"
,
"tray"
,
"-shared"
,
"-viewonly"
])
self
.
vnc_server
=
subprocess
.
Popen
([
"x11vnc"
,
"-shared"
,
"-viewonly"
])
#popen.wait, popen.poll...
try
:
print
(
"retour:"
,
self
.
server
.
returncode
)
except
:
print
(
"code retour indisponible"
)
self
.
btn_start
.
pack_forget
()
self
.
btn_stop
.
pack
(
side
=
TOP
)
self
.
started
=
True
...
...
@@ -152,7 +153,7 @@ class VnClic(object):
#subprocess.run(["x11vnc", "-R", "stop"])
subprocess
.
Popen
([
"x11vnc"
,
"-R"
,
"stop"
])
#self.vnc_server.terminate() #popen
try
:
print
(
"retour:"
,
self
.
server
.
returncode
)
except
:
...
...
@@ -167,13 +168,17 @@ class VnClic(object):
""
def
receive
(
self
,
data
,
host
):
if
host
==
self
.
ip
:
print
(
"Dropped"
)
elif
data
[
0
:
10
]
==
"#START####"
:
if
data
[
0
:
10
]
==
"#START####"
:
self
.
addUser
(
host
,
data
[
10
:])
elif
data
[
0
:
10
]
==
"#STOP#####"
:
self
.
removeUser
(
host
)
def
message
(
self
,
code
):
if
code
==
0
:
self
.
showError
(
"La connexion a échoué. Veuillez vérifier que le programme n'est pas déjà lancé."
)
elif
code
==
1
:
self
.
mainWindow
()
def
addUser
(
self
,
host
,
name
=
""
):
if
host
not
in
self
.
user_list
:
name
=
name
[
0
:
15
]
...
...
@@ -196,13 +201,12 @@ class VnClic(object):
self
.
msg_user
.
pack
(
side
=
TOP
,
padx
=
4
)
else
:
self
.
msg_user
.
pack_forget
()
def
setViewonly
(
self
):
if
self
.
input
.
get
():
subprocess
.
Popen
([
"x11vnc"
,
"-R"
,
"noviewonly"
])
else
:
subprocess
.
Popen
([
"x11vnc"
,
"-R"
,
"viewonly"
])
def
view
(
self
,
host
):
"Execute the remote desktop viewer"
...
...
@@ -222,7 +226,7 @@ class VnClic(object):
def
save
(
self
):
"Save preferences"
def
save
(
self
):
config
=
configparser
.
ConfigParser
()
config
[
'Server'
]
=
{}
...
...
@@ -236,12 +240,15 @@ class VnClic(object):
config
[
'Port'
]
=
{}
config
[
'Port'
][
'vnc'
]
=
self
.
preference
[
'Port'
][
'vnc'
]
config
[
'Port'
][
'vnclic'
]
=
self
.
preference
[
'Port'
][
'vnclic'
]
self
.
config
.
save
(
config
)
def
quit
(
self
):
try
:
self
.
stop
()
self
.
w
.
quit
()
except
:
pass
self
.
w
.
quit
()
if
__name__
==
'__main__'
:
VnClic
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment