【Python 代码】类似SADPTool工具,搜索海康设备

 

海康设备搜索器搜索协议解析

 参考:海康设备搜索器搜索协议解析_凹凸慢的水博客的技术博客_51CTO博客

 【Python 代码】类似SADPTool工具,搜索海康设备_第1张图片

vEthernet 可能会影响搜索,可以禁用。 

 代码:

import socket
import re
import uuid

def getUUID():
  return (str(uuid.uuid4())).upper()

ANY = "0.0.0.0"
DES_IP = "239.255.255.250"
PORT = 37020
# xml_str = b'B2D5D4D2-808C-40F6-87CD-694C05C2B274inquiry '
xml_str = f'{getUUID()}inquiry'
xml_str=bytes(xml_str,encoding='utf-8')
# 创建UDP socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
# 允许端口复用
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# 绑定监听多播数据包的端口
s.bind((ANY, PORT))
# 声明该socket为多播类型
s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255)
# 加入多播组,组地址由第三个参数制定
s.setsockopt(
  socket.IPPROTO_IP,
  socket.IP_ADD_MEMBERSHIP,
  socket.inet_aton(DES_IP) + socket.inet_aton(ANY)
)
s.setblocking(False)
s.sendto(xml_str, (DES_IP, PORT))
while True:
  try:
    data, address = s.recvfrom(2048)
  except Exception as e:
    # print(e)
    pass
  else:
    print(address)
    print(data)
    try:
      IPv4 = re.search(re.compile(r"(.*?)", re.S), str(data))[1]
      MAC = re.search(re.compile(r"(.*?)", re.S), str(data))[1]
      DeviceDescription = re.search(re.compile(r"(.*?)", re.S), str(data))[1]
    except TypeError:
      pass
    else:
      # print(data)
      print("IPv4: {}".format(IPv4))
      print("MAC: {}".format(MAC))
      print("DeviceDescription:{}".format(DeviceDescription))

'''
b'
\r\n
BC06ADDD-2934-4B51-8246-3604E13B0A83\r\n
inquiry\r\n
147256\r\n
DS-2CD3T86FWDA4-LS\r\n
DS-2CD3T86FWDA4-LS20220517AACHJ90521185\r\n
8000\r\n
80\r\n
80-7c-62-b3-53-85\r\n
192.168.0.64\r\n
255.255.255.0\r\n
192.168.0.1\r\n
::\r\n
::\r\n
64\r\n
false\r\
0\r\n
1\r\n
V5.7.1build 220309\r\n
V7.3 build 211201\r\n
2022-07-09 09:07:09\r\n
true\r\n
false\r\n
1\r\n
true\r\n
true\r\n
true\r\n
true\r\n
true\r\n
true\r\n
true\r\n
f23c32b6630844732d6af341e3c32e0a8d11ec9e1d721a845fdc55397818374c\r\n
flase\r\n
8443\r\n
true\r\n
true\r\n
true\r\n
true\r\n
true\r\n
\r\n'
'''

相关链接:

PyQt5 实现类似海康的设备搜索工具_文若书生的博客-CSDN博客简述 使用IP地址组播技术,实现海康的设备搜索功能,只要设备接入局域网就能够被搜索到。效果图.功能代码:1.scan_device_ui.py 布局文件# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'scan_device.ui'## Created by: PyQt5 UI code generator 5.15.2## WARNING: Any...https://blog.csdn.net/ZHOUYONGXYZ/article/details/120223188?python socket发送组播数据_python3通过udp实现组播数据的发送和接收操作_方2郭的博客-CSDN博客本文主要通过对海康摄像头进行抓包,模拟发送了udp包,并抓取摄像头返回的数据包,解析并提取相关信息。通过抓包发现,海康摄像头发送、接收数据使用udp协议,后来比较发现,使用python模拟起来比较简单。由于摄像头内置了udp协议的server端程序,本文主要使用python模拟客户端发送udp数据包。客户端代码import socketimport reANY = "0.0.0.0"DES_IP ...https://blog.csdn.net/weixin_35763513/article/details/112894077

你可能感兴趣的:(笔记,python,网络,开发语言)