Java 向连接到 Wi-Fi 网络的所有设备发送通知

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26032364/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 01:44:42  来源:igfitidea点击:

Send notification to all the devices connected to a Wi-Fi network

javaandroidiosnetworkingwifi

提问by Gokul Nath KP

Is there any way to send a notification to the devices which are connected to a particular Wi-Fi network?

有没有办法向连接到特定 Wi-Fi 网络的设备发送通知?

Say, I have a Wi-Fi network named "My Wi-Fi", which is not secured, that is any one can connect. A public network.

比如说,我有一个名为“我的 Wi-Fi”的 Wi-Fi 网络,它是不安全的,任何人都可以连接。一个公共网络。

There may be N-number of users connected to "My Wi-Fi". These users can perform any kind of transaction, say online payment.

可能有 N 个用户连接到“我的 Wi-Fi”。这些用户可以执行任何类型的交易,比如在线支付。

Now if I want to turn off or shut down "My Wi-Fi" router or access point, these transactions may fail.

现在,如果我想关闭或关闭“我的 Wi-Fi”路由器或接入点,这些交易可能会失败。

So before shutting down, I want to send a text notification to all the users connected to "My Wi-Fi" network. (User does not have any kind of app in their device, to push the notification.)

因此,在关闭之前,我想向所有连接到“我的 Wi-Fi”网络的用户发送文本通知。(用户在他们的设备中没有任何类型的应用程序来推送通知。)

Is this possible?

这可能吗?

采纳答案by Makyen

There is no standard method of sending (pushing) a message to all devices attached to a Wi-Fi network. If there was a way, it would be easy to find the specification and point to how it is to be done. Unfortunately, it is difficult to prove the absence of something.

没有向连接到 Wi-Fi 网络的所有设备发送(推送)消息的标准方法。如果有办法,很容易找到规范并指出如何完成。不幸的是,很难证明某些东西不存在。

As you clearly realized, it would be possible to do so if an appropriate page which you control was open in a browser, or application running, on their device. You could develop a framework where users have to sign on and keep a page open, or application running, in order to connect to your Wi-Fi.

正如您清楚地意识到的那样,如果您控制的适当页面在浏览器中打开或在他们的设备上运行的应用程序中打开,则可以这样做。您可以开发一个框架,让用户必须登录并保持页面打开或应用程序运行,才能连接到您的 Wi-Fi。

Given that you control the router, it would be physically possible for you to write code which intercepted the packets being transmitted through the router and inserted such a warning within the HTTP of pages being sent to the various connected devices. This assumes that they are using HTTP to view normal pages. You could, of course, also insert a warning in other protocols. Depending on your jurisdiction this might be illegal, or have other legal issues. I would consider doing so to be a Bad Idea?.

鉴于您控制了路由器,您实际上可以编写代码来拦截通过路由器传输的数据包,并在发送到各种连接设备的页面的 HTTP 中插入这样的警告。这假设他们使用 HTTP 查看普通页面。当然,您也可以在其他协议中插入警告。根据您的司法管辖区,这可能是非法的,或者有其他法律问题。我会认为这样做是个坏主意?。

回答by KiranCK

Wild suggestion, you could intercept the http request and reply with a custom http response which can display a banner saying that the router is about to be shutdown. With this any ongoing payment transactions would fail. Hope it helps.

大胆的建议,您可以拦截 http 请求并使用自定义 http 响应进行回复,该响应可以显示一个横幅,说明路由器即将关闭。这样,任何正在进行的支付交易都会失败。希望能帮助到你。

回答by Churk

There is no uniform answers to this. It depends on if you have access to the connection list. If you have access to the AP then it simplify things easier. If not, you can attempt to send a message all 254 IP addresses: 192.168.1.[1-254].

对此没有统一的答案。这取决于您是否有权访问连接列表。如果您可以访问 AP,那么事情就变得更简单了。如果没有,您可以尝试发送所有 254 个 IP 地址的消息:192.168.1.[1-254]。

For users who are connected using WinXP or older. You can send a message using net send

对于使用 WinXP 或更早版本连接的用户。您可以使用发送消息net send

For users who are connected using WinVista or newer. You can send a message using msg

对于使用 WinVista 或更新版本连接的用户。您可以使用发送消息msg

For users who are connected using Linux. You can try: smbclient -M hostname message goes here

对于使用 Linux 连接的用户。你可以试试:smbclient -M hostname message goes here

For users who are connected using MAC. I have not seen this yet.

对于使用 MAC 连接的用户。我还没有看到这个。