def get_device_name(ip_addr):
""" get the device friendly name for an IP address """
try:
conn = httplib.HTTPConnection(ip_addr + ":8008")
conn.request("GET", "/ssdp/device-desc.xml")
resp = conn.getresponse()
if resp.status == 200:
status_doc = resp.read()
try:
xml = ElementTree.fromstring(status_doc)
device_element = xml.find("{urn:schemas-upnp-org:device-1-0}" + "device")
return device_element.find("{urn:schemas-upnp-org:device-1-0}" + "friendlyName").text
except ElementTree.ParseError:
return ""
else:
return ""
except:
# unable to get a name - this might be for many reasons
# e.g. a non chromecast device on the network that responded to the search
return ""
cc_device_finder.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录