检测手机连接到无线网络 - C#

发布于 2024-12-24 02:34:09 字数 705 浏览 6 评论 0原文

我正在用 C# 编程,我想在无线网络 (Wi-Fi) 中检测手机(名称、IP 地址、RSSI...),然后计算我的计算机和手机之间的距离 实际上,我能够检测到连接到同一网络的计算机名称:

using System.DirectoryServices;
...

List<String> _ComputerNames = new List<String>();
String _ComputerSchema = "Computer";
DirectoryEntry _WinNTDirectoryEntries = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry _AvailDomains in _WinNTDirectoryEntries.Children)
{
    foreach (DirectoryEntry _PCNameEntry in _AvailDomains.Children)
    {
        if (_PCNameEntry.SchemaClassName.ToLower().Contains(_ComputerSchema.ToLower()))
        {
            _ComputerNames.Add(_PCNameEntry.Name);
        }
    }
}

但我找不到连接到同一 Wi-Fi 网络的手机。

我该如何解决这个问题? 谢谢!

I'm programming in C# and i want to detect a cell phone(Name, IP address, RSSI, ...) in Wireless Network (Wi-Fi) to calculate after that the distance between my computer and the cell phone
Actually, I'm able to detect computers name connected to the same network with :

using System.DirectoryServices;
...

List<String> _ComputerNames = new List<String>();
String _ComputerSchema = "Computer";
DirectoryEntry _WinNTDirectoryEntries = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry _AvailDomains in _WinNTDirectoryEntries.Children)
{
    foreach (DirectoryEntry _PCNameEntry in _AvailDomains.Children)
    {
        if (_PCNameEntry.SchemaClassName.ToLower().Contains(_ComputerSchema.ToLower()))
        {
            _ComputerNames.Add(_PCNameEntry.Name);
        }
    }
}

But I cannot find my cell phone that is connect to the same wi-fi network.

How can I resolve this problem ?
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

靖瑶 2024-12-31 02:34:09

我认为 ActiveDirectory 不太适合您,您可能需要与接入点本身更密切地合作以获取 RSSI 值。除非您对所有电话都属于 ActiveDirectory 的一部分有特定的领域知识,否则就像 Jean 所说:您只能获得 MAC 地址,可能是 IP 地址和 RSSI 值。

如果您只对距离感兴趣,您可能需要使用特定设备测试一系列距离,并使用 RSSI 距离列表根据新设备的 RSSI 值来估计其距离。

您将遇到的一个问题是,一台设备可能有 X 个 RSSI 值,另一台设备有 2X RSSI 值,并且它们很可能是完全相同的距离。不过,如果您只对手机感兴趣,我预计波动不会那么严重。

更准确的方法是设置多个接入点,并使用一点 数学,其优点还在于为您提供距离和方向,相当于位置

I dont think ActiveDirectory is going to work too well for you here, your likely going to need to work more closely with the access point itself to fetch the RSSI values. Unless there is a particular domain knowledge you have about all phones being part of an ActiveDirectory its like Jean said: you only get MAC address, possibly IP address and the RSSI value.

If you are only interested in distance you will likely need to test out a range of distances with a particular device and use the RSSI-distance list you to guestimate the distance of a new device based on the RSSI value for it.

A problem you will encounter is you might have X RSSI Value for one device, and 2X RSSI Value for another device and they could very well be the exact same distance. Although if you are only interested in phones I would expect the fluctuation to be less severe.

A more accurate way to do this would be to have multiple Access Points setup and triangulate the device's position with a bit of math, the plus side of this is also giving you distance as well as direction, amounting to location

一身仙ぐ女味 2024-12-31 02:34:09

除非我弄错了,否则只有 Wi-Fi 接入点本身才能访问完整的设备列表。即使如此,它也不知道每个设备是什么类型。它知道每个设备的 MAC 地址,并且可能知道为其分配的 IP(假设它也是 DHCP 服务器),但除此之外,该设备可以是从笔记本电脑到电视的任何设备。

如果您是网络管理员,那么我可以看到这可能会有什么用处 - 如果您制定了仅某些设备旨在连接到网络的策略,那么追捕“恶意”设备就有意义了。否则,我看不出有任何充分的理由来尝试进一步帮助您。

Unless I am mistaken, only the Wi-Fi access point itself will have access to the full list of devices. Even then, it doesn't know what type each device is. It knows the MAC address of each device, and it may know the IP it was allocated (assuming it is also a DHCP server), but beyond that the device could be anything from a laptop to a television.

If you are a network administrator, then I can see how this might be useful - if you have a policy where only certain devices are intended to connect to the network, then it makes sense to hunt down "rogue" devices. Otherwise, I can't see any good reason to try and help you any further.

且行且努力 2024-12-31 02:34:09

如果您知道手机的 IP 地址,则可以尝试 ping 设备。

bool isIpReachable(string ipAddress)
{
    Ping pingSender = new Ping();
    PingOptions options = new PingOptions();
    options.DontFragment = true;

    string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    byte[] buffer = Encoding.ASCII.GetBytes(data);
    int timeout = 120;

    try
    {
        PingReply reply = pingSender.Send(ipAddress, timeout, buffer, options);
        return reply.Status == IPStatus.Success;
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error: " + ex.Message);
    }
    return false;
}

If you know what ip address the phone has then you can try and ping the device.

bool isIpReachable(string ipAddress)
{
    Ping pingSender = new Ping();
    PingOptions options = new PingOptions();
    options.DontFragment = true;

    string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    byte[] buffer = Encoding.ASCII.GetBytes(data);
    int timeout = 120;

    try
    {
        PingReply reply = pingSender.Send(ipAddress, timeout, buffer, options);
        return reply.Status == IPStatus.Success;
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error: " + ex.Message);
    }
    return false;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文