如何使用 C++ 获取 LAN 网络上 IP 摄像机的所有 MAC 地址和端口号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9605905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get all MAC address and port number of IP camera on a LAN network using C++?
提问by TTGroup
I have many IP cameras on the same LAN network. I want to get MAC address and port number of each camera, although I don't know ip address of them. Furthermore, if the ip and port of a camera is changed, how to detect it?
我在同一个 LAN 网络上有很多 IP 摄像机。我想获取每个摄像头的 MAC 地址和端口号,虽然我不知道它们的 IP 地址。另外,如果摄像机的ip和端口发生了变化,如何检测?
I've also searched on internet about this problem. Most of people responded using some of the Window functions such as SendARP () or using command line "arp -a". But if do it, then get all MAC address of the LAN network that regardless of the camera's or the computer's.
我也在互联网上搜索过这个问题。大多数人使用一些Window函数如SendARP()或使用命令行“arp -a”来响应。但是如果这样做,那么无论相机还是计算机,都会获取LAN网络的所有MAC地址。
Please help me!
请帮我!
回答by Josh Siok
I would start with a port scanner such as nmap and look for information that will identify your IP cameras.
我会从端口扫描仪(例如 nmap)开始,并寻找可以识别您的 IP 摄像机的信息。
nmap -A -T4 192.168.0.0/24
If all of your cameras are the same, you may be able to detect them by the OS information returned.
如果您的所有摄像头都相同,您或许能够通过返回的操作系统信息检测到它们。
You might also be able to do a banner grab to determine the port:
您也可以通过抓取横幅来确定端口:
nmap -sV --script=banner 192.168.0.0/24
Use C++ to parse the nmap output. Change the network address range to fit your network.
使用 C++ 解析 nmap 输出。更改网络地址范围以适合您的网络。
回答by drew010
Are all of the cameras you are looking for made by the same company? If so, the MAC addresses may all share a common prefix that was assigned to that company, or do they support HTTP or some other protocol you could use to probe the camera to identify it as well?
您要找的所有相机都是同一家公司生产的吗?如果是这样,MAC 地址可能都共享一个分配给该公司的公共前缀,或者它们是否支持 HTTP 或其他一些您可以用来探测摄像机以识别它的协议?
If they don't share similar MAC addresses, you can still use other methods to find all the cameras.
如果它们不共享相似的 MAC 地址,您仍然可以使用其他方法找到所有摄像机。
One way I might approach the problem:
我可能会解决这个问题的一种方法:
For each IP address in your network range {
Send ARP request for IP address
If ARP response received {
Check MAC address of ARP response
If MAC address matches camera MFR {
// Add to list
} else {
// Probe IP address for device specific webpage or service
If probe matches {
// Add to list
}
}
}
}
You may find that the cameras support some SNMP
commands that you could use as an identifying factor. In the worst case, you could send an HTTP
packet to the IP address and see if the host responds with the webpage for the camera assuming each one has an embedded web server. Chances are, there is at least one protocol you could use to identify the cameras out of all of your network devices.
您可能会发现相机支持一些SNMP
可以用作识别因素的命令。在最坏的情况下,您可以向HTTP
IP 地址发送一个数据包,然后假设每个主机都有一个嵌入式 Web 服务器,然后查看主机是否以摄像头的网页响应。很有可能,您至少可以使用一种协议来识别所有网络设备中的摄像头。
回答by Kaz
Do your IP cameras broadcast any identifying information, e.g with mDNS packets? Maybe you can catch these broadcasts. Google for "mDNS" or "Zeroconf".
您的 IP 摄像机是否广播任何识别信息,例如使用 mDNS 数据包?也许你可以收看这些广播。谷歌搜索“mDNS”或“Zeroconf”。