日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mac版本 sadptool_海康 设备 发现(SADPTool原理)

發布時間:2023/12/10 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mac版本 sadptool_海康 设备 发现(SADPTool原理) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

SADPTool原理:

向239.255.255.250:37020發送基于ONVIF協議的 udp 組播,設備會監聽?239.255.255.250:37020,收到指令,會向 發送組播的機器,返回設備信息,也會向239.255.255.250:37020 發送 設備信息的 組播。

發送 報文(Uuid是Guid,每次都生成一個新的,用同一個,我沒有試過,可不可以)

12D17626-0DE1-48DB-97E3-40B106467932inquiry

返回報文

12D17626-0DE1-48DB-97E3-40B106467932

inquiry

139991

CS-C6TC-32WFR

CS-C6TC-32WFR0120170327CCCH738231995

8000

80

54-c4-15-9a-38-72

172.20.20.100

255.255.255.0

172.20.20.254

false

0

1

V5.2.3build 180804

V1.0 build 180731

2018-10-18 21:30:10

N/A

true

false

通過 wireshark 抓包發現,發送?ONVIF協議后,還會 廣播 一個 包

但是不知道,是做何作用,我用SharpPcap 模擬發送了一個EarthNet II 的包,這個包 是固定不變的。

EarthNet II 的包,C# 原生 Socket 貌似不支持,raw_Socket 寫起來太繁瑣了,SharpPcap 另一個用處是可以基于網卡抓包。

搜索設備代碼:

public void SearchDecives()

{

//EtherNetII 協議

byte[] SearchIpCameraByte = new byte[]{

0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,//目的地Mac

0x00 ,0x15 ,0x5d ,0xe6 ,0xaa ,0x0b ,//源地址Mac

0x80 ,0x33 ,//協議類型(0x8033螢石自定義類型)

0x21 ,0x02,//發送數據

0x01 ,0x42 ,0x00 ,0x00 ,0x24 ,0x03 ,0x06 ,0x04 ,0x03 ,0x00 ,0x13 ,0x82 ,0x00 ,0x15 ,0x5d ,0xe6,

0xaa ,0x0b ,0xa9 ,0xfe ,0x50 ,0x50 ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 ,0x00 ,0x00,

0x00 ,0x00 ,0x00 ,0x00 ,0xfe ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x64 ,0x7e ,0x5d ,0xb0,

0x9e ,0x93 ,0xcd ,0x07 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,

};

var devices = CaptureDeviceList.Instance;

Console.Write("---------------------------");

// differentiate based upon types

foreach (ICaptureDevice dev in devices)

{

if (dev is AirPcapDevice)

{

// process as an AirPcapDevice

}

else if (dev is WinPcapDevice)

{

dev.Open();

//dev.Capture();

//dev.StartCapture();

dev.SendPacket(SearchIpCameraByte);

Thread.Sleep(1000);

//dev.StopCapture();

//dev.Close();

// process as an WinPcapDevice

}

else if (dev is LibPcapLiveDevice)

{

// process as an LibPcapLiveDevice

}

}

return;

}

/// /// 查找設備

///

///

///

private void button1_Click(object sender, EventArgs e)

{

SendInQuiry();

SearchDecives();

SendMSearch();

}

/// /// 搜索upnp 設備

/// 向ssdp服務地址239.255.255.250:1900組播發送數據

///

public void SendMSearch()

{

//向ssdp服務地址239.255.255.250:1900組播發送數據

IPEndPoint ipend = new IPEndPoint(IPAddress.Any, 0);

UdpClient client = new UdpClient(ipend);

client.EnableBroadcast = false;

client.JoinMulticastGroup(IPAddress.Parse("239.255.255.250"));

IPEndPoint multicast = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900);

byte[] buf = Encoding.Default.GetBytes("M-SEARCH * HTTP/1.1\r\nHOST:239.255.255.250:1900\r\nMAN:\"ssdp:discover\"\r\nST:upnp:rootdevice\r\nMX:3\r\n\r\n");

client.Send(buf, buf.Length, multicast);

//異步接收數據

//client.BeginReceive(new AsyncCallback(ReceiveBack), client);

//設置網絡超時時間,一段時間未接收到數據時自動退出

//client.Client.ReceiveTimeout = 150;

//單播接收數據

//while (true)

//{

// byte[] value = client.Receive(ref ipend);

// string msg = Encoding.Default.GetString(value);

// //OLog.Info(msg);

// Console.WriteLine(msg + "-" + ipend.Address.ToString());

//}

}

/// /// 發送設備探究

/// 向ssdp服務地址239.255.255.250:37020組播發送數據

///

public void SendInQuiry()

{

var uuid = Guid.NewGuid().ToString().ToUpper();

//A207AD1A-962B-480B-A32C-4B0D98CBA0D4inquiry

var InQuiry = new byte[]{

0x3c ,0x3f ,0x78 ,0x6d ,0x6c ,0x20,

0x76 ,0x65 ,0x72 ,0x73 ,0x69 ,0x6f ,0x6e ,0x3d ,0x22 ,0x31 ,0x2e ,0x30 ,0x22 ,0x20 ,0x65 ,0x6e,

0x63 ,0x6f ,0x64 ,0x69 ,0x6e ,0x67 ,0x3d ,0x22 ,0x75 ,0x74 ,0x66 ,0x2d ,0x38 ,0x22 ,0x3f ,0x3e,

0x3c ,0x50 ,0x72 ,0x6f ,0x62 ,0x65 ,0x3e ,0x3c ,0x55 ,0x75 ,0x69 ,0x64 ,0x3e

}.

Concat(System.Text.Encoding.UTF8.GetBytes(uuid)).//uuid

Concat(new byte[]{

0x3c ,0x2f ,0x55 ,0x75 ,0x69 ,0x64 ,0x3e ,0x3c ,0x54 ,0x79 ,0x70 ,0x65 ,0x73 ,0x3e ,0x69,

0x6e ,0x71 ,0x75 ,0x69 ,0x72 ,0x79 ,0x3c ,0x2f ,0x54 ,0x79 ,0x70 ,0x65 ,0x73 ,0x3e ,0x3c ,0x2f,

0x50 ,0x72 ,0x6f ,0x62 ,0x65 ,0x3e

}).ToArray();

IPEndPoint ipend = new IPEndPoint(IPAddress.Any, 0);

UdpClient client = new UdpClient(ipend);

client.EnableBroadcast = false;

client.JoinMulticastGroup(IPAddress.Parse("239.255.255.250"));

IPEndPoint multicast = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 37020);

client.Send(InQuiry, InQuiry.Length, multicast);

}

監聽組播代碼:

private void button2_Click(object sender, EventArgs e)

{

//接收組播數據

Thread t = new Thread(new ThreadStart(RecvThread));

t.IsBackground = true;

t.Start();

//Socket recv_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

//recv_socket.Bind(new IPEndPoint(IPAddress.Any, 1900));

//recv_socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, ReceiveMessage, recv_socket);

}

/// /// 獲取 ssdp 組播

/// ssdp地址固定:239.255.255.250:1900

/// 海康設備組播到 37020 端口

///

void RecvThread()

{

//綁定組播端口

UdpClient client = new UdpClient(37020);

client.EnableBroadcast = false;

client.JoinMulticastGroup(IPAddress.Parse("239.255.255.250"));

IPEndPoint mult = null;

while (true)

{

byte[] buf = client.Receive(ref mult);

string msg = Encoding.Default.GetString(buf);

Console.WriteLine(msg);

MessageBox.Show(msg);

//Console.WriteLine(mult.Address.ToString());

}

}

還可以用 ARP 映射原理 獲取 局域網 所有機器的MAC地址,根據MAC 前6位判斷是 哪家生產的設備,同一企業生產的 網絡設備mac地址 前6位一般是固定的。

海康設備Mac地址 都是54-c4-15 開頭的

我這里用的是 cmd arp -a,取arp映射的,也可以 sharppcap抓包,或者Windows api 發送arp 協議 包,取返回值

private static string GetARPResult()

{

Process p = null;

string output = string.Empty;

try

{

p = Process.Start(new ProcessStartInfo("arp", "-a")

{

CreateNoWindow = true,

UseShellExecute = false,

RedirectStandardOutput = true

});

output = p.StandardOutput.ReadToEnd();

}

catch (Exception ex)

{

throw new Exception("IPInfo: Error Retrieving 'arp -a' Results", ex);

}

finally

{

if (p != null)

{

p.Close();

}

}

return output;

}

總結

以上是生活随笔為你收集整理的mac版本 sadptool_海康 设备 发现(SADPTool原理)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。