FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-zeroconf/examples/browser.py at master · decabyte/python-zeroconf · GitHub
decabyte
python-zeroconf
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-zeroconf
/
examples
/
browser.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
49 lines (40 loc) · 1.6 KB
Breadcrumbs
python-zeroconf
/
examples
/
browser.py
Copy path
File metadata and controls
executable file
·
49 lines (40 loc) · 1.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python
from
__future__
import
absolute_import
,
division
,
print_function
,
unicode_literals
""" Example of browsing for a service (in this case, HTTP) """
import
logging
import
socket
import
sys
from
time
import
sleep
from
zeroconf
import
ServiceBrowser
,
ServiceStateChange
,
Zeroconf
def
on_service_state_change
(
zeroconf
,
service_type
,
name
,
state_change
):
print
(
"Service %s of type %s state changed: %s"
%
(
name
,
service_type
,
state_change
))
if
state_change
is
ServiceStateChange
.
Added
:
info
=
zeroconf
.
get_service_info
(
service_type
,
name
)
if
info
:
print
(
" Address: %s:%d"
%
(
socket
.
inet_ntoa
(
info
.
address
),
info
.
port
))
print
(
" Weight: %d, priority: %d"
%
(
info
.
weight
,
info
.
priority
))
print
(
" Server: %s"
%
(
info
.
server
,))
if
info
.
properties
:
print
(
" Properties are:"
)
for
key
,
value
in
info
.
properties
.
items
():
print
(
" %s: %s"
%
(
key
,
value
))
else
:
print
(
" No properties"
)
else
:
print
(
" No info"
)
print
(
'
\n
'
)
if
__name__
==
'__main__'
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
if
len
(
sys
.
argv
)
>
1
:
assert
sys
.
argv
[
1
:]
==
[
'--debug'
]
logging
.
getLogger
(
'zeroconf'
).
setLevel
(
logging
.
DEBUG
)
zeroconf
=
Zeroconf
()
print
(
"
\n
Browsing services, press Ctrl-C to exit...
\n
"
)
browser
=
ServiceBrowser
(
zeroconf
,
"_http._tcp.local."
,
handlers
=
[
on_service_state_change
])
try
:
while
True
:
sleep
(
0.1
)
except
KeyboardInterrupt
:
pass
finally
:
zeroconf
.
close
()
Back
|
FazBrowse Home
|
New Git URL