def probe_camera_info(ip, port): # check to see if ip/port is simulated for simh in sim_hosts: if str(port)!=simh[1]: continue try: if str(socket.gethostbyname(simh[0]))!=ip: continue except: continue global sim_cameras rtspuri = "rtsp://"+ip+":"+str(port)+"/live.sdp" if rtspuri not in sim_cameras: sim_cameras[rtspuri]=len(sim_cameras.keys()) camid=("simsn",sim_prefix+str(sim_cameras[rtspuri])) return (rtspuri,[camid],{"manufacturer":"Simulated","serial":camid[1]},True) if office and dbhost: r=list(dbp.search("ip={} and port={} and rtspurl:*".format(ip,port),size=1)) if r: rtspuri=r[0]["_source"]["rtspurl"] dinfo={ k:r[0]["_source"][k] for k in ["manufacturer","model","serial"] if k in r[0]["_source"] } return (rtspuri,[("rtspurl",rtspuri)],dinfo,False) for passcode in get_passcodes(ip,port)+passcodes: print("OnVIF discovery over {}:{} {}".format(ip,port,passcode), flush=True) up=passcode.split(":") desc=safe_discover(ip, port, up[0], up[1]) print(json.dumps(desc,indent=2), flush=True) if desc: if "uri" in desc: rtspuri=desc["uri"][0].replace("rtsp://","rtsp://"+passcode+"@") if passcode!=":" else desc["uri"][0] camids=[] dinfo={} if "device" in desc: if "SerialNumber" in desc['device']: camids.append(("device.SerialNumber",desc['device']['SerialNumber'])) if "Manufacturer" in desc['device']: dinfo["manufacturer"]=desc['device']['Manufacturer'] if "Model" in desc['device']: dinfo["model"]=desc['device']['Model'] if "SerialNumber" in desc['device']: dinfo["serial"]=desc['device']['SerialNumber'] if "networks" in desc: for network1 in desc['networks']: if "HwAddress" in network1: camids.append(("networks.HwAddress",network1['HwAddress'])) return (rtspuri,camids,dinfo,False) return (None,[],{},Flase)
def probe_camera_info(ip, port, user='******', passwd='admin'): desc = safe_discover(ip, port, user, passwd) if desc: rtspuri = desc["uri"][0] rtspuri = rtspuri.replace('rtsp://', "rtsp://" + user + ":" + passwd + "@") camid = (None, None) if "device" in desc: return (rtspuri, ("device.SerialNumber", desc['device']['SerialNumber']), desc) if "networks" in desc: return (rtspuri, ("networks.HwAddress", desc['networks'][0]['HwAddress']), desc) if port in sim_ports: global sim_cameras rtspuri = "rtsp://" + ip + ":" + str(port) + "/live.sdp" if rtspuri not in sim_cameras: sim_cameras[rtspuri] = len(sim_cameras.keys()) camid = ("simsn", sim_prefix + str(sim_cameras[rtspuri])) return (rtspuri, camid, {}) return (None, None, None)
def parse_nmap_xml(nmapxml, sim_ports, user='******', passwd='admin'): root = ET.fromstring(nmapxml) for host1 in root.findall('host'): ip = host1.find("address").attrib['addr'] ports = host1.find('ports') for port1 in ports.findall('port'): if(port1.attrib['protocol'] == 'tcp'): port = int(port1.attrib['portid']) print("To test " + ip + ":" + str(port), flush=True) desc=safe_discover(ip, port, user, passwd) if desc: print("Found onvif device service", flush=True) camid=("MAC",desc["MAC"]) if "MAC" in desc else None if not camid: if "NetworkInterfaces" in desc: if desc["NetworkInterfaces"]: camid=("NetworkInterfaces.Info.HwAddress",desc['NetworkInterfaces'][0]['Info']['HwAddress']) if not camid: if "DeviceInformation" in desc: camid=("DeviceInformation.SerialNumber",desc['DeviceInformation']['SerialNumber']) rtspuri = desc["MediaStreamUri"]["Uri"] rtspuri = rtspuri.replace('rtsp://', "rtsp://"+user+":"+passwd+"@") yield (rtspuri,camid,desc) continue else: print("Trying simulated camera", flush=True) if port in sim_ports: for state1 in port1.findall('state'): if state1.attrib['state'] == "open": print("Found simulated camera", flush=True) rtspuri = "rtsp://"+ip+":"+str(port)+"/live.sdp" index=sim_cameras[rtspuri] if rtspuri in sim_cameras else len(sim_cameras.keys()) camid=("simsn",sim_prefix+str(index)) yield (rtspuri,camid,{})