在 C 中获取 LAN 上的设备列表 [英] Get list of devices on LAN in C

查看:15
本文介绍了在 C 中获取 LAN 上的设备列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取连接到本地网络的可用设备列表(它们的 IP 地址或主机名应该没问题).我在 C# 中有一些示例,但我找不到任何使用 C/C++ 的示例.我熟悉 BSD 套接字 API,只是为了澄清一下.

I'd like to get a list of available devices (their IP address or hostname should be fine) connected to my local network. I've got some examples in C#, but I couldn't find any sample using C/C++. I'm familiar with the BSD socket API, just to clarify.

我有一个存根"的想法:也许我应该确定我 LAN 上的设备可能属于的 IP 地址范围,然后确定它们是否存在.G.回应 PING,或类似的东西.我怎样才能做到这些?

I have a "stub" kind of idea: maybe I should determine the range of the IP addresses that the devices on my LAN can potentially belong to, and then determine if they e. g. respond to PING, or something like that. How could I achieve these?

我希望我的应用程序在 Linux 和 iOS 上运行.这就是为什么我更喜欢 BSD 套接字,或者最多是 Foundation/GNUstep(尽管它们是用 Objective-C 编写的).

I want my application to run on Linux and iOS. That's why I'd prefer BSD sockets, or at a maximum, Foundation/GNUstep (although they are written in Objective-C).

推荐答案

你也可以例如向 224.0.0.1 发送 ICMP 回显请求数据包.这是每个节点都应响应的特殊全节点多播地址(除非防火墙规则或网络策略设置阻止它).

You can also e.g. send an ICMP echo request packet to 224.0.0.1. This is a special all-nodes multicast address every node should respond to (except if a firewall rule or network policy setting prevents it).

这篇关于在 C 中获取 LAN 上的设备列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆